随笔分类 -  rust

1 2 3 下一页

rust libc
摘要:https://cloud.tencent.com/developer/article/1620862 // use std::thread; // fn main() { // let child = thread::spawn(move || { // println!("Hello, I am 阅读全文

posted @ 2021-01-07 19:13 tycoon3 阅读(627) 评论(0) 推荐(0) 编辑

rust test
摘要:单元测试 测试(test)是这样一种 Rust 函数:它保证其他部分的代码按照所希望的行为正常 运行。测试函数的函数体通常会进行一些配置,运行我们想要测试的代码,然后 断言(assert)结果是不是我们所期望的。 大多数单元测试都会被放到一个叫 tests 的、带有 #[cfg(test)] 属性 阅读全文

posted @ 2021-01-04 15:04 tycoon3 阅读(573) 评论(0) 推荐(0) 编辑

rust 条件编译
摘要:条件编译可以通过两种不同的操作符实现,如下: - cfg属性:在属性位置中使用#[cfg(...)] - cfg!宏:在布尔表达式中使用cfg!(...) Configuration conditional checks are possible through two different oper 阅读全文

posted @ 2021-01-04 14:41 tycoon3 阅读(428) 评论(0) 推荐(0) 编辑

Effectively Using Iterators In Rust
摘要:iter()通过引用遍历项目 into_iter()遍历项目,将其移至新范围 iter_mut()遍历项目,为每个项目提供可变的引用 因此,for x in my_vec { ... }本质上等效于my_vec.into_iter().for_each(|x| ... )-将my_vec的两个元素都 阅读全文

posted @ 2020-12-30 11:27 tycoon3 阅读(111) 评论(0) 推荐(0) 编辑

rust FnMut 闭包
摘要:fn consume_with_relish<F>(mut func: F) where F: FnMut() -> String { // `func` consumes its captured variables, so it cannot be run more // than once p 阅读全文

posted @ 2020-12-29 15:42 tycoon3 阅读(242) 评论(0) 推荐(0) 编辑

rust 迭代器
摘要:https://blog.csdn.net/guiqulaxi920/article/details/78823541 fn main() { // Basic Range (exclusive on the right) for i in 1..11 { print!("{} ", i); } p 阅读全文

posted @ 2020-12-28 17:39 tycoon3 阅读(132) 评论(0) 推荐(0) 编辑

Rust:迭代器(Iterator)
摘要:https://github.com/rustomax/rust-iterators 1、迭代器是什么? 迭代器(iterator)负责遍历序列中的每一项和决定序列何时结束的逻辑,迭代器是 惰性的(lazy)。迭代器模式允许你对一个项的序列进行某些处理。 let v = vec![1, 2, 3]; 阅读全文

posted @ 2020-12-28 17:25 tycoon3 阅读(494) 评论(0) 推荐(0) 编辑

rust async
摘要:use futures::{ self, executor}; use std::thread; use std::time; async fn song() { loop { println!("song!"); thread::sleep(time::Duration::from_secs(5) 阅读全文

posted @ 2020-12-28 15:45 tycoon3 阅读(216) 评论(0) 推荐(0) 编辑

rust clone
摘要:use std::sync::Arc; let foo = Arc::new(vec![1.0, 2.0, 3.0]); // The two syntaxes below are equivalent. let a = foo.clone(); let b = Arc::clone(&foo); 阅读全文

posted @ 2020-12-28 14:58 tycoon3 阅读(151) 评论(0) 推荐(0) 编辑

rust panicked
摘要:use std::thread; use std::time; use std::sync::mpsc; fn main() { let (tx, rx) : (mpsc::Sender<i32>, mpsc::Receiver<i32>) = mpsc::channel(); //drop(rx) 阅读全文

posted @ 2020-12-28 14:30 tycoon3 阅读(170) 评论(0) 推荐(0) 编辑

Rust“所有权”思想
摘要:fn main() { let s1 = String::from("hello"); let s2 = s1; println!("s1 : {}", s1); let s3 = s2.clone(); println!("s2 : {}", s2); println!("s3 : {}", s3 阅读全文

posted @ 2020-12-28 11:35 tycoon3 阅读(322) 评论(0) 推荐(0) 编辑

Rust学习 mutex
摘要:use std::sync::Mutex; fn main() { let m = Mutex::new(5); //Mutex<i32>, 智能指针 { let mut num = m.lock().unwrap(); //等待,阻塞线程, //返回MutexGuard, 智能指针,实施deref 阅读全文

posted @ 2020-12-28 11:10 tycoon3 阅读(859) 评论(0) 推荐(1) 编辑

How Arc works in Rust
摘要:The Atomic Reference Counter (Arc) type is a smart pointer that lets you share immutable data across threads in a thread-safe way. I couldn’t find any 阅读全文

posted @ 2020-12-28 10:41 tycoon3 阅读(62) 评论(0) 推荐(0) 编辑

Handmade Rust Part 1: Introduction & Allocators
摘要:Blog series Part 1: Introduction & Allocators Part 2: Unq, an allocator-aware Box Part 3: Containers Part 4: Generating Vulkan bindings Welcome to Han 阅读全文

posted @ 2020-12-28 10:26 tycoon3 阅读(88) 评论(0) 推荐(0) 编辑

rust 强制转换
摘要:use std::ops::Deref; struct MyBox<T>(T); impl<T> MyBox<T> { fn new(x: T) -> MyBox<T> { MyBox(x) } } //impl<T> Deref for MyBox<T> { // type Target = T; 阅读全文

posted @ 2020-12-28 09:52 tycoon3 阅读(417) 评论(0) 推荐(0) 编辑

引用与借用
摘要:https://kaisery.github.io/trpl-zh-cn/ch04-02-references-and-borrowing.html 示例 4-5 中的元组代码有这样一个问题:我们必须将 String 返回给调用函数,以便在调用 calculate_length 后仍能使用 Stri 阅读全文

posted @ 2020-12-28 09:28 tycoon3 阅读(351) 评论(0) 推荐(0) 编辑

candidate #1: `std::clone::Clone`
摘要:struct Rec { width : u32, length : u32 } fn process(rec1: Rec) -> Rec { let mut rec2 = rec1; rec2.width = 10; rec2.length = 11; rec2 } fn main() { let 阅读全文

posted @ 2020-12-26 22:28 tycoon3 阅读(141) 评论(0) 推荐(0) 编辑

value used here after move
摘要:[root@bogon fnmut]# cat src/main.rs #[derive(Debug)] struct f_closure{ name: String, } impl f_closure{ fn fn_call( self) -> String{ self.name } } fn g 阅读全文

posted @ 2020-12-26 12:08 tycoon3 阅读(346) 评论(0) 推荐(0) 编辑

cannot borrow as mutable
摘要:cat src/main.rs #[derive(Debug)] struct f_closure{ name: String, } impl f_closure{ fn fn_call( self) -> String{ self.name } } fn get_string<T>(name: S 阅读全文

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

move occurs because `self.name` has type `std::string::String`, which does not implement the `Copy` trait
摘要:cat src/main.rs #[derive(Debug)] struct f_closure{ name: String, } impl f_closure{ fn fn_call(& self) -> String{ self.name } } fn main() { let name = 阅读全文

posted @ 2020-12-26 11:29 tycoon3 阅读(1888) 评论(0) 推荐(0) 编辑

1 2 3 下一页

导航