pub struct Error { /* private fields */ }Expand description
Error type returned across all Sift crates.
Implementations§
Source§impl Error
impl Error
Sourcepub fn new<E>(kind: ErrorKind, err: E) -> Error
pub fn new<E>(kind: ErrorKind, err: E) -> Error
Initializes an Error from a standard error type.
This constructor wraps a standard library error (or any type implementing
std::error::Error) into a Sift error with the specified ErrorKind.
§Arguments
kind- The category of error that occurrederr- The underlying error to wrap
§Example
use sift_error::{Error, ErrorKind};
use std::io;
let io_error = io::Error::new(io::ErrorKind::NotFound, "file not found");
let sift_error = Error::new(ErrorKind::IoError, io_error);Sourcepub fn new_msg<S>(kind: ErrorKind, msg: S) -> Error
pub fn new_msg<S>(kind: ErrorKind, msg: S) -> Error
Initializes an Error with a generic message string.
This constructor creates an error from a string message without wrapping an underlying error type.
§Arguments
kind- The category of error that occurredmsg- A string message describing the error
§Example
use sift_error::{Error, ErrorKind};
let error = Error::new_msg(ErrorKind::NotFoundError, "resource not found");Sourcepub fn new_general<S>(msg: S) -> Error
pub fn new_general<S>(msg: S) -> Error
Initializes a general catch-all type of Error.
Contributors should be careful not to use this unless strictly necessary. Prefer more specific ErrorKind variants when possible.
§Arguments
msg- A string message describing the error
§Example
use sift_error::Error;
let error = Error::new_general("unexpected condition occurred");Sourcepub fn new_arg_error<S>(msg: S) -> Error
pub fn new_arg_error<S>(msg: S) -> Error
Used for user-errors that have to do with bad arguments.
This is a convenience constructor for argument validation errors.
§Arguments
msg- A string message describing the argument validation failure
§Example
use sift_error::Error;
fn validate_age(age: i32) -> Result<(), Error> {
if age < 0 {
return Err(Error::new_arg_error("age must be non-negative"));
}
Ok(())
}Sourcepub fn new_empty_response<S>(msg: S) -> Error
pub fn new_empty_response<S>(msg: S) -> Error
Creates an error for empty gRPC responses.
Tonic response types usually return optional types that we need to handle; if responses are empty then this is the appropriate way to initialize an Error for that situation, though this has never been observed in practice.
§Arguments
msg- A string message describing the empty response situation
§Example
use sift_error::Error;
// This would typically be used when a gRPC response is unexpectedly empty
let error = Error::new_empty_response("asset response was empty");Trait Implementations§
Source§impl Error for Error
impl Error for Error
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request