4个版本
| 0.1.3 | 2024年1月31日 | 
|---|---|
| 0.1.2 | 2024年1月23日 | 
| 0.1.1 | 2024年1月23日 | 
| 0.1.0 | 2024年1月23日 | 
787 in 算法
每月 28次下载
17KB
450 行
简介
这个crate主要是个人异步代码片段的堆放地,这些代码片段可能被用于其他ToMT项目。
但如果这个crate对其他人有用,请告诉我们。
用法
tomt_async::同步::互斥锁
use std::sync::Arc;
use tomt_async::sync::Mutex;
async fn main()
{
    let shared_mutex = Arc::new(Mutex::new(0));
    do_something(shared_mutex.clone()).await;
}
async do_something(
    shared_mutex: Arc<Mutex<i32>>
) {
    let mut lock = shared_mutex.lock().await;
    *lock = *lock + 1;
    // lock is released on drop, though it's highly recommended to avoid
    // calling any async funcs while the lock is held
}
tomt_async::集合::栈
use tomt_async::collections::Stack;
async fn main()
{
    let stack = Stack::<i32>::new();
    stack.push(5).await;
    stack.push(8).await;
    do_something(stack).await;
}
async fn do_something<T: std::fmt::Debug>(
    stack: Stack<T>
) {
    while let Some(item) = stack.pop().await {
        println!("Item = {item:?}");
    }
}