type ByteOption = Option<u8>;
fn increment_or_zero(x: ByteOption) -> u8 {
match x {
ByteOption::Some(y) => y + 1,
ByteOption::None => 0,
}
}
impl Coin {
fn value_in_cents(&self) -> u8 {
match self {
Self::Penny => 1,
Self::Nickel => 5,
Self::Dime => 10,
Self::Quarter => 25,
}
}
}
/// Type size assertion where the first parameter
/// is a type and the second is the expected size.
#[macro_export]
macro_rules! static_assert_size {
($ty:ty, $size:expr) => {
const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()];
// ^ Note the underscore here.
}
}
static_assert_size!(Option<Box<String>>, 8); // 1.
static_assert_size!(usize, 8); // 2.
首先編譯時 rustc 加入 -C profile-generate
然後執行這個程式跑一跑你的測試資料後會產生記錄檔
再來第二次編譯 rustc 加入 -C profile-use
會根據你剛剛跑的結果來最佳化編譯
如果你沒打 --bin 也可以編
#[repr(align(16))]
enum Align16 {
Foo { foo: u32 },
Bar { bar: u32 },
}
BufReader::buffer and BufWriter::buffer
Cell::from_mut
Cell::as_slice_of_cells
DoubleEndedIterator::nth_back
Option::xor
[{i,u}{8,16,32,64,128,size}::reverse_bits] and Wrapping::reverse_bits
slice::copy_within
read more
任天堂也用Rust了。這是任天堂的 rust tool chain跟庫的集合
這些庫還不成熟,還在開發中,非常需要有時間的人幫忙開發
歡迎大家的加入
<div class="marker" />
可以使用/>來對tag做描述,詳細請看 changelog