feat: add FromArc and ArcInto (#1288) (#1326)

This commit is contained in:
Myriad-Dreamin 2025-02-19 22:57:34 +08:00 committed by GitHub
parent 0c64bea89e
commit d3e7027d67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -23,3 +23,33 @@ pub type ImmutStr = Arc<str>;
pub type ImmutBytes = Arc<[u8]>;
/// An immutable path.
pub type ImmutPath = Arc<Path>;
/// A trait for converting an `Arc<T>` into `Self`.
pub trait FromArc<T> {
/// Converts an `Arc<T>` into `Self`.
fn from_arc(arc: Arc<T>) -> Self;
}
impl<S, T> FromArc<S> for T
where
Arc<S>: Into<T>,
{
fn from_arc(arc: Arc<S>) -> T {
arc.into()
}
}
/// A trait for converting `Arc<T>` into `Self`.
pub trait ArcInto<T> {
/// Converts `Arc<T>` into `Self`.
fn arc_into(self: Arc<Self>) -> T;
}
impl<S, T> ArcInto<T> for S
where
Arc<S>: Into<T>,
{
fn arc_into(self: Arc<Self>) -> T {
self.into()
}
}