Struct busrt::rpc::RpcError

source ·
pub struct RpcError { /* private fields */ }

Implementations§

source§

impl RpcError

source

pub fn new(code: i16, data: Option<Vec<u8>>) -> Self

source

pub fn code(&self) -> i16

source

pub fn data(&self) -> Option<&[u8]>

source

pub fn method(err: Option<Vec<u8>>) -> Self

Examples found in repository?
examples/broker_custom_rpc.rs (line 29)
22
23
24
25
26
27
28
29
30
31
    async fn handle_call(&self, event: RpcEvent) -> RpcResult {
        match event.parse_method()? {
            "test" => Ok(Some("passed".as_bytes().to_vec())),
            "ping" => {
                let params: PingParams = rmp_serde::from_slice(event.payload())?;
                Ok(params.message.map(|m| m.as_bytes().to_vec()))
            }
            _ => Err(RpcError::method(None)),
        }
    }
More examples
Hide additional examples
examples/client_rpc_handler.rs (line 49)
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    async fn handle_call(&self, event: RpcEvent) -> RpcResult {
        match event.parse_method()? {
            "test" => {
                let mut payload = BTreeMap::new();
                payload.insert("ok", true);
                Ok(Some(rmp_serde::to_vec_named(&payload)?))
            }
            "get" => {
                let mut payload = BTreeMap::new();
                payload.insert("value", self.counter.load(atomic::Ordering::SeqCst));
                Ok(Some(rmp_serde::to_vec_named(&payload)?))
            }
            "add" => {
                let params: AddParams = rmp_serde::from_slice(event.payload())?;
                self.counter
                    .fetch_add(params.value, atomic::Ordering::SeqCst);
                Ok(None)
            }
            _ => Err(RpcError::method(None)),
        }
    }
source

pub fn not_found(err: Option<Vec<u8>>) -> Self

source

pub fn params(err: Option<Vec<u8>>) -> Self

source

pub fn parse(err: Option<Vec<u8>>) -> Self

source

pub fn invalid(err: Option<Vec<u8>>) -> Self

source

pub fn internal(err: Option<Vec<u8>>) -> Self

source

pub fn convert_data(v: impl Display) -> Vec<u8>

Converts displayable to Vec

Trait Implementations§

source§

impl Debug for RpcError

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for RpcError

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Error for RpcError

1.30.0 · source§

fn source(&self) -> Option<&(dyn Error + 'static)>

The lower-level source of this error, if any. Read more
1.0.0 · source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type based access to context intended for error reports. Read more
source§

impl From<Error> for RpcError

source§

fn from(e: Error) -> RpcError

Converts to this type from the input type.
source§

impl From<Error> for RpcError

source§

fn from(e: Error) -> RpcError

Converts to this type from the input type.
source§

impl From<Error> for RpcError

source§

fn from(e: Error) -> RpcError

Converts to this type from the input type.
source§

impl From<Error> for RpcError

source§

fn from(e: Error) -> RpcError

Converts to this type from the input type.
source§

impl From<Error> for RpcError

source§

fn from(e: Error) -> RpcError

Converts to this type from the input type.
source§

impl TryFrom<&RpcEvent> for RpcError

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(event: &RpcEvent) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.