Into_inner for an async_std::sync::{Arc, RwLock};

While using the standard std::sync::Arc<std::sync::RwLock<T>> wrapper would allow one to remove the pointee seemlessly, the async_std version of Arc<RwLock<T>> appear to have issues with the common method. How do I extract T from the async_std version of Arc<RwLock<T>> ?

use std::sync::Arc;
use async_std::sync:::RwLock;

fn try_unwrap<T>(ptr: Arc<RwLock<T>>) -> Result<T, Arc<RwLock<T>>> {
    let rw_lock = Arc::try_unwrap(ptr)?;
    Ok(RwLock::into_inner(rw_lock))
}

This also works exactly the same for std::sync::RwLock

1 Like