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
impl Error
Sourcepub fn internal<A: Into<String>, B: Into<String>>(
message: A,
details: B,
) -> Self
pub fn internal<A: Into<String>, B: Into<String>>( message: A, details: B, ) -> Self
Internal Server Error
Sourcepub fn not_found<T: Into<String>>(details: T) -> Self
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 }
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more