tinymist_std/concepts/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
mod takable;
use std::{borrow::Cow, path::Path, sync::Arc};

pub use takable::*;

pub mod cow_mut;

mod query;
pub use query::*;

mod read;
pub use read::*;

mod marker;
pub use marker::*;

#[cfg(feature = "typst")]
pub mod typst;

/// An immutable string.
pub type ImmutStr = Arc<str>;
/// An immutable byte slice.
pub type ImmutBytes = Arc<[u8]>;
/// An immutable path.
pub type ImmutPath = Arc<Path>;
/// A copy-on-write static string.
pub type CowStr = Cow<'static, str>;

/// 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()
    }
}