Struct Error

Source
pub struct Error {
    pub code: StatusCode,
    pub message: String,
    pub details: String,
}
Expand description

API error format

Fields§

§code: StatusCode

Error code

§message: String

Error message

§details: String

Error details

Implementations§

Source§

impl Error

Source

pub fn internal<A: Into<String>, B: Into<String>>( message: A, details: B, ) -> Self

Internal Server Error

Source

pub fn not_found<T: Into<String>>(details: T) -> Self

Generate 404 not found error.

Examples found in repository?
examples/api.rs (line 25)
20    pub fn single(&self, id: usize) -> Result<Call, resty::Error> {
21        let calls = self.calls.read().unwrap();
22        if id < calls.len() {
23            Ok(calls[id].clone())
24        } else {
25            Err(resty::Error::not_found(""))
26        }
27    }
28
29    pub fn add(&self, call: Call) -> Result<Call, resty::Error> {
30        self.calls.write().unwrap().push(call.clone());
31        Ok(call)
32    }
33
34    pub fn update(&self, id: usize, call: Call) -> Result<Call, resty::Error> {
35        let mut calls = self.calls.write().unwrap();
36        if id < calls.len() {
37            calls[id] = call.clone();
38            Ok(call)
39        } else {
40            Err(resty::Error::not_found(""))
41        }
42    }
Source

pub fn bad_request<A: Into<String>, B: Into<String>>( message: A, details: B, ) -> Self

Generate 400 bad request error.

Source

pub fn method_not_allowed<A: Into<String>, B: Into<String>>( message: A, details: B, ) -> Self

Generate 405 method not allowed error.

Trait Implementations§

Source§

impl Debug for Error

Source§

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

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

impl Default for Error

Source§

fn default() -> Error

Returns the “default value” for a type. Read more
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl Into<Response> for Error

Source§

fn into(self) -> Response

Converts this type into the (usually inferred) input type.
Source§

impl Into<Response> for Error

Source§

fn into(self) -> Response

Converts this type into the (usually inferred) input type.

Auto Trait Implementations§

§

impl Freeze for Error

§

impl RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnwindSafe for Error

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.