Skip to content

Rust Feature

Posted on:June 5, 2023 at 02:41 AM

1.利用类型系统和 borrow checker 实现的不需要 gc 的内存安全

2.编译时检查的 data race

3.直接由核心团队设计和维护的 cargo, rustup 等工具

fn use_lock(mutex: &Mutex<Vec<i32>>) {
    // acquire the lock, taking ownership of a guard;
    // the lock is held for the rest of the scope
    let mut guard = lock(mutex);

    // access the data by mutably borrowing the guard
    let vec = access(&mut guard);

    // vec has type `&mut Vec<i32>`
    vec.push(3);

    // lock automatically released here, when `guard` is destroyed
}

多样化的并发方式


actor model