ENQT-GmbH / remoc

Remoc 🦑 — Remote multiplexed objects, channels and RPC for Rust
https://crates.io/crates/remoc
Other
173 stars 16 forks source link

Ability to return custom errors #21

Open CowBoy4mH3LL opened 2 months ago

CowBoy4mH3LL commented 2 months ago

Say I have a custom error SError{message:String} and I implement From<std:io:Error> on it. Now, from a function, say, fn(&self) -> Result<(),SError> in an rtc::remote labelled trait, I get an std:io:error as a result of calling await on some other async function. Even if I have implemented the From cast from Error to SError, it does not seem to be able to cast between the output Result forms. Any idea why?

surban commented 2 months ago

Your custom error type must be serializable and it must implement From<CallError>.

For example:

// Custom error type that can convert from CallError.
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub enum IncreaseError {
    Overflow,
    Call(CallError),
}

impl From<CallError> for IncreaseError {
    fn from(err: CallError) -> Self {
        Self::Call(err)
    }
}