reflexo_typst2vec/
cast.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
pub trait FromTypst<T>: Sized {
    fn from_typst(value: T) -> Self;
}

pub trait IntoTypst<T>: Sized {
    fn into_typst(self) -> T;
}

impl<T, U> IntoTypst<U> for T
where
    U: FromTypst<T>,
{
    fn into_typst(self) -> U {
        U::from_typst(self)
    }
}

pub trait TryFromTypst<T>: Sized {
    type Error;

    fn try_from_typst(value: T) -> Result<Self, Self::Error>;
}

pub trait TryIntoTypst<T>: Sized {
    type Error;

    fn try_into_typst(self) -> Result<T, Self::Error>;
}

impl<T, U> TryIntoTypst<U> for T
where
    U: TryFromTypst<T>,
{
    type Error = U::Error;

    fn try_into_typst(self) -> Result<U, Self::Error> {
        U::try_from_typst(self)
    }
}