随笔分类 - rust
摘要:macro_rules! four { () => {1 + 3}; } fn main(){ println!("{}", 1+four!()); println!("{}", 2+four![]); println!("{}", 3+four!{}); } HIR阶段是将 你撸的代码转为AST。
阅读全文
摘要:将源代码转为高级中间表示,在将其转为中级中间表示,在将其转为LLVM IR, 最终输出机器码。 rust 租借检查 选项优化,代码生成(宏, 范型) , 都是在MIR层。
阅读全文
摘要:pub trait Summary { fn summarize_author(&self) -> String; fn summarize(&self) -> String { format!("(Default Read more from {}...)", self.summarize_aut
阅读全文
摘要:之前定义的结构体,都是不含引用的。 如果想定义含引用的结构体,请定义生命周期注解 #[warn(unused_variables)] struct ImportantExcerpt<'a> { part: &'a str, } fn main() { let novel = String::from
阅读全文
摘要:记录一下自己理解的生命周期。 每个变量都有自己的生命周期。 在c++里生命周期好比作用域, 小的作用域的可以使用大作用域的变量。 如果把这里的每个作用域取个名,那么就相当于rust里的生命周期注解。 拿例子说事一: 如果按照c++的方式来理解, 这个x和r的作用域是一样的,都是在main函数中。 但
阅读全文
摘要:fn main(){ for i in 1..10 { for j in 1..i+1 { print!("{}*{}={:<2} ",j,i,i*j); } print!("\n"); } }
阅读全文
摘要:Available codegen options: -C ar=val -- this option is deprecated and does nothing -C linker=val -- system linker to link outputs with -C link-arg=val
阅读全文
摘要:➜ hello_cargo git:(master) ✗ rustc --print code-models Available code models: small kernel medium large
阅读全文
摘要:Available CPUs for this target: native - Select the CPU of the current host (currently haswell). amdfam10 athlon athlon-4 athlon-fx athlon-mp athlon-t
阅读全文
摘要:Rust中的每个值都具有特定的数据类型。 基础类型: 整数,浮点数,布尔值和字符 i8,i16,i32,i64,i64,i128,isize, u8,u16,u32,u64,u64,u128,usize, f64,f32 bool: true false char 复合类型:元组和数组 元组: le
阅读全文
摘要:当前,以下关键字具有所描述的功能。 as-执行原始类型转换,消除包含项目的特定特征的歧义,或在useand extern crate语句中重命名项目async-返回a Future而不是阻塞当前线程await-暂停执行直到a的结果Future准备好break -立即退出循环const -定义常量项目
阅读全文
摘要:Mac rust环境 rust安装: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh rust更新: rustup update rust卸载: rustup self uninstall rust检查: rustc --
阅读全文