随笔分类 -  rust

上一页 1 2 3

Rust 异步编程,async await
摘要:应用:简单HTTP服务器 https://learnku.com/docs/async-book/2018/http_server_example/4789 //例子二 use futures::{ self, executor}; async fn learn_song() { println!( 阅读全文

posted @ 2020-12-25 12:02 tycoon3 阅读(1420) 评论(0) 推荐(0) 编辑

rust async
摘要:cargo check [root@bogon async]# cargo check Checking own v0.1.0 (/data2/rust/async) error[E0670]: `async fn` is not permitted in the 2015 edition --> 阅读全文

posted @ 2020-12-25 11:53 tycoon3 阅读(889) 评论(0) 推荐(0) 编辑

rust self
摘要:src/main.rs #[derive(Debug)] struct MyType { name: String } impl MyType { fn do_something(self, age: u32) { //等价于 fn do_something(self: Self, age: u32 阅读全文

posted @ 2020-12-25 11:21 tycoon3 阅读(237) 评论(0) 推荐(0) 编辑

rust Deref
摘要:Deref <T> trait用于自定义解除引用运算符(*)的行为。如果实现Deref <T>特征,则可以将智能指针视为参考。 因此,在引用上工作的代码也可以用在智能指针上。 常规引用 常规引用是一种指向某个值的指针,该值存储在其他地方。下面来看一个简单的例子来创建i32类型值的引用,然后使用引用运 阅读全文

posted @ 2020-12-24 17:57 tycoon3 阅读(342) 评论(0) 推荐(0) 编辑

rust explicit
摘要:cat src/main.rs // 生命周期 `'a` 和 `'b`。这两个生命周期都必须至少要和 `print_refs` // 函数的一样长。 fn print_refs<'a, 'b>(x: &'a i32, y: &'b i32) { println!("x is {} and y is 阅读全文

posted @ 2020-12-24 17:43 tycoon3 阅读(73) 评论(0) 推荐(0) 编辑

rust move
摘要:// 此函数取倒堆分配的内存的所有权 fn destroy_box(c: Box<i32>) { println!("Destroying a box that contains {}", c); // `c` 被销毁且内存得到释放 } fn main() { // 栈分配的整型 let x = 5 阅读全文

posted @ 2020-12-24 17:20 tycoon3 阅读(222) 评论(0) 推荐(0) 编辑

rust drop
摘要:Drop Drop trait 只有一个方法:drop,当一个对象离开作用域时会自动调用该方法。Drop trait 的主要作用是释放实现者实例拥有的资源。 Box,Vec,String,File,以及 Process 是一些实现了 Drop trait 来释放资源的类型的例子。Drop trait 阅读全文

posted @ 2020-12-24 17:10 tycoon3 阅读(182) 评论(0) 推荐(0) 编辑

rust 可变变量
摘要:变量绑定默认是不可变的,但加上 mut 修饰语后变量就可以改变。 fn main() { let _immutable_binding = 1; let mut mutable_binding = 1; println!("Before mutation: {}", mutable_binding) 阅读全文

posted @ 2020-12-24 17:03 tycoon3 阅读(187) 评论(0) 推荐(0) 编辑

Rust学习(32):智能指针-Rc<T>
摘要:cat src/main.rs use std::rc::Rc; struct Owner { name: String, // ...other fields } struct Gadget { id: i32, owner: Rc<Owner>, // ...other fields } fn 阅读全文

posted @ 2020-12-24 16:53 tycoon3 阅读(207) 评论(0) 推荐(0) 编辑

rust 高级编程
摘要:高级编程 https://learnku.com/docs/nomicon/2018/33-life-cycle/4714 rust-by-example- http://llever.com/rust-by-example-cn/variable_bindings/mut.html 箱子、栈和堆 阅读全文

posted @ 2020-12-24 16:13 tycoon3 阅读(300) 评论(0) 推荐(0) 编辑

rust 所有权
摘要:cat src/main.rs fn main() { let x= String::from("42"); let y=x; println!("value of x :{}",x); } cargo build Compiling own v0.1.0 (/data2/rust/own) war 阅读全文

posted @ 2020-12-24 15:58 tycoon3 阅读(421) 评论(0) 推荐(0) 编辑

rust智能指针
摘要:demo1 fn main() { let a = 5; let b = &a; if a == *b { println!("Equal"); } else { println!("Not equal"); } } cargo run Finished dev [unoptimized + deb 阅读全文

posted @ 2020-12-24 15:16 tycoon3 阅读(154) 评论(0) 推荐(0) 编辑

rust mod
摘要:[root@bogon app1]# cat Cargo.toml [package] name = "app1" version = "0.1.0" authors = ["magnate <liangeaglejun@sina.com>"] edition = "2018" # See more 阅读全文

posted @ 2020-10-23 17:13 tycoon3 阅读(296) 评论(0) 推荐(0) 编辑

cargo
摘要:cargo --version [root@bogon ~]# cargo --version cargo 1.47.0 (f3c7e066a 2020-08-28) You have new mail in /var/spool/mail/root [root@bogon ~]# 使用 cargo 阅读全文

posted @ 2020-10-23 16:44 tycoon3 阅读(1001) 评论(0) 推荐(0) 编辑

上一页 1 2 3

导航