mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-15 08:41:37 +00:00
17 lines
558 B
Plaintext
17 lines
558 B
Plaintext
---
|
||
title: 第 8 章 Create 与模块
|
||
date: '2025-01-12'
|
||
tags: [Rust]
|
||
---
|
||
|
||
有时,可能需要对函数的内联进行微观管理,但我们通常会把这种优化留给编译器。可以使用 `#[inline]` 属性进行微观管理:
|
||
|
||
```rust
|
||
#[inline]
|
||
fn add(x: i32, y: i32) -> i32 {
|
||
x + y
|
||
}
|
||
```
|
||
|
||
只有在一种特定的情况下,如果没有 `#[inline]`,就不会发生内联。当一个 crate 中定义的函数或方法在另一个 crate 中被调用时,Rust 不会将其内联,除非它是泛型的或名曲的标记为 `#[inline]`。
|