Files
DefectingCat.github.io/content/posts/chapter-8-crate-and-module.mdx
2025-03-18 09:57:13 +08:00

17 lines
558 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
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]`。