Untitled

mail@pastecode.io avatar
unknown
rust
2 months ago
1.1 kB
1
Indexable
Never
pub enum Function1Error {
    Variant1,
    Variant2,
}

pub fn function1() -> Result<(), Function1Error> {
    Err(Function1Error::Variant1)
}

pub enum Function2Error {
    Variant1,
    Variant2,
}

pub enum Function3Error {
    Function1Variant1,
    Function1Variant2,
    Function2Variant1,
    Function2Variant2,
    Variant1,
    Variant2,
}

impl From<Function1Error> for Function3Error {
    fn from(err: Function1Error) -> Self {
        match err {
            Function1Error::Variant1 => { Function3Error::Variant1 }
            Function1Error::Variant2 => { Function3Error::Variant2 }
        }
    }
}

impl From<Function2Error> for Function3Error {
    fn from(err: Function2Error) -> Self {
        match err {
            Function2Error::Variant1 => { Function3Error::Variant1 }
            Function2Error::Variant2 => { Function3Error::Variant2 }
        }
    }
}

pub fn function2() -> Result<(), Function2Error> {
    Err(Function2Error::Variant1)
}


pub fn function3() -> Result<(), Function1Error> {
    function1()?;
    function2()?;
    Err(Function1Error::Variant1)
}
Leave a Comment