Helix Keymap

================================================================= = CHAPTER 1 RECAP = Use the h,j,k,l keys to move the cursor. Type : to enter Command mode. The q / quit and q! / quit! commands will exit Helix. The former fails when there are unsaved changes. The latter discards them. The w / write command will save the file. The wq / write-quit command will do both. Type d to delete the character at the cursor....

April 6, 2025 · rikaaa0928

Rust tokio: Send与Sync

tokio中,返回的future无脑实现Send,因为tokio异步框架并不能保证单个异步任务绑定某个真实线程执行,实现Send表示这个future可以安全的跨线程执行。 Sync表示并发安全,需要跨异步任务调用的必须是Sync,可以套Mutex实现非Sync转Sync,再套Arc实现clone。 // Sync 类型: Arc // 当 T: Sync Mutex // 当 T: Send RwLock // 当 T: Send AtomicBool AtomicI32 Vec // 当 T: Sync String &T // 当 T: Sync // 非 Sync 类型: RefCell // 内部可变性不是线程安全的 Cell // 同上 Rc // 引用计数不是线程安全的 *mut T // 裸指针

October 27, 2024 · rikaaa0928

Rust: 可变和引用

mut a: &mut i32 mut a表示a可变,可以被重新绑定 &表示(不可变)引用 &mut表示可变引用,即*a可变,可以被重新绑定 测试验证代码 fn change_i_mut_ref(i:&mut i32){ *i=2; // 给引用绑定新值,i 不可变,*i 指向的变量可变 } // fn change_i_mut_ref_err(i:&mut i32){ // i=xxxx; // i 不可变,不可重新绑定,等于什么都不行 // } fn change_mut_i(mut i:i32){ i=4; } fn change_mut_i_ref(mut i:&i32){ i=&5; } fn change_mut_i_mut_ref_change_i(mut i:&mut i32){ // i=&5; //会报错,因为 &5 的类型是 &i32, &mut 5 的类型是 &mut i32 // i=&mut 5; //一样会报错,因为 &mut 5 生命周期仅在函数内,函数返回后,i引用的值会被回收 } fn change_mut_i_mut_ref_change_ref(mut i:&mut i32){ *i=7; } #[tokio::test] async fn my_test1()-> crate::Result<()> { let mut i=1i32; println!...

January 10, 2024 · rikaaa0928