本文簡要介紹rust語言中 Macro core::include_bytes
的用法。
用法
macro_rules! include_bytes {
($file : expr $(,) ?) => { ... };
}
包含一個文件作為對字節數組的引用。
該文件相對於當前文件定位(類似於如何找到模塊)。提供的路徑在編譯時以特定於平台的方式進行解釋。因此,例如,使用包含反斜杠 \
的 Windows 路徑的調用將無法在 Unix 上正確編譯。
這個宏將產生一個&'static [u8; N]
類型的表達式,它是文件的內容。
例子
假設同一目錄下有兩個文件,內容如下:
文件'spanish.in':
adiós
文件'main.rs':
fn main() {
let bytes = include_bytes!("spanish.in");
assert_eq!(bytes, b"adi\xc3\xb3s\n");
print!("{}", String::from_utf8_lossy(bytes));
}
編譯'main.rs' 並運行生成的二進製文件將打印“adiós”。
相關用法
- Rust include_bytes用法及代碼示例
- Rust include_str用法及代碼示例
- Rust include用法及代碼示例
- Rust i64.overflowing_add_unsigned用法及代碼示例
- Rust i128.log2用法及代碼示例
- Rust i16.log10用法及代碼示例
- Rust i128.checked_div用法及代碼示例
- Rust i64.abs用法及代碼示例
- Rust i16.wrapping_add_unsigned用法及代碼示例
- Rust i128.checked_next_multiple_of用法及代碼示例
- Rust isize.unstable_div_floor用法及代碼示例
- Rust i32.saturating_mul用法及代碼示例
- Rust isize.swap_bytes用法及代碼示例
- Rust i128.overflowing_pow用法及代碼示例
- Rust i64.checked_add用法及代碼示例
- Rust i16.wrapping_sub用法及代碼示例
- Rust i128.overflowing_sub用法及代碼示例
- Rust i64.saturating_abs用法及代碼示例
- Rust isize.from_ne_bytes用法及代碼示例
- Rust i16.wrapping_shr用法及代碼示例
- Rust i128.overflowing_shr用法及代碼示例
- Rust i128.overflowing_shl用法及代碼示例
- Rust i16.unstable_div_floor用法及代碼示例
- Rust i16.wrapping_abs用法及代碼示例
- Rust i128.checked_sub_unsigned用法及代碼示例
注:本文由純淨天空篩選整理自rust-lang.org大神的英文原創作品 Macro core::include_bytes。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。