pub struct Error { /* private fields */ }Expand description
An error returned by Rest.
The error is deliberately small (a kind plus an optional boxed source) so Result<T, Error>
stays cheap to move around. Inspect it with kind, or use the shortcuts
status and api_error.
discord.js counterpart: DiscordAPIError, HTTPError and RateLimitError (@discordjs/rest).
§Examples
use djs_model::rest::ErrorCode;
match rest.create_message(channel_id, &"hi".into()).await {
Ok(message) => println!("sent {}", message.id),
Err(error)
if error
.api_error()
.is_some_and(|api| api.code == ErrorCode::MissingPermissions) =>
{
eprintln!("missing permissions");
}
Err(error) => eprintln!("request failed: {error}"),
}Implementations§
Source§impl Error
impl Error
Sourcepub const fn kind(&self) -> &ErrorKind
pub const fn kind(&self) -> &ErrorKind
Returns what went wrong.
discord.js counterpart: the class of the error @discordjs/rest rejects with (DiscordAPIError, HTTPError, RateLimitError).
Sourcepub fn into_parts(self) -> (ErrorKind, Option<Box<dyn Error + Send + Sync>>)
pub fn into_parts(self) -> (ErrorKind, Option<Box<dyn Error + Send + Sync>>)
Consumes the error, returning its kind and underlying source.
discord.js counterpart: none (JavaScript errors are not taken apart).
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Auto Trait Implementations§
impl !RefUnwindSafe for Error
impl !UnwindSafe for Error
impl Freeze for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin 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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
Fallible version of [
ToCompactString::to_compact_string()] Read more§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
Converts the given value to a [
CompactString]. Read more