pub struct JsNativeError { /* private fields */ }Expand description
Native representation of an ideal Error object from Javascript.
This representation is more space efficient than its JsObject equivalent,
since it doesn’t need to create a whole new JsObject to be instantiated.
Prefer using this over JsError when you don’t need to throw
plain JsValues as errors, or when you need to inspect the error type
of a JsError.
§Examples
let native_error = JsNativeError::uri().with_message("cannot decode uri");
match native_error.kind() {
JsNativeErrorKind::Uri => { /* handle URI error*/ }
_ => unreachable!(),
}
assert_eq!(native_error.message(), "cannot decode uri");Implementations§
Source§impl JsNativeError
impl JsNativeError
Sourcepub const fn kind(&self) -> &JsNativeErrorKind
pub const fn kind(&self) -> &JsNativeErrorKind
Returns the kind of this native error.
Sourcepub const fn aggregate(errors: Vec<JsError>) -> Self
pub const fn aggregate(errors: Vec<JsError>) -> Self
Creates a new JsNativeError of kind AggregateError from a list of JsErrors, with
empty message and undefined cause.
§Examples
let inner_errors = vec![
JsNativeError::typ().into(),
JsNativeError::syntax().into()
];
let error = JsNativeError::aggregate(inner_errors);
assert!(matches!(
error.kind(),
JsNativeErrorKind::Aggregate(errors) if errors.len() == 2
));Sourcepub const fn is_aggregate(&self) -> bool
pub const fn is_aggregate(&self) -> bool
Check if it’s a JsNativeErrorKind::Aggregate.
Sourcepub const fn error() -> Self
pub const fn error() -> Self
Creates a new JsNativeError of kind Error, with empty message and undefined cause.
§Examples
let error = JsNativeError::error();
assert!(matches!(error.kind(), JsNativeErrorKind::Error));Sourcepub const fn is_error(&self) -> bool
pub const fn is_error(&self) -> bool
Check if it’s a JsNativeErrorKind::Error.
Sourcepub const fn eval() -> Self
pub const fn eval() -> Self
Creates a new JsNativeError of kind EvalError, with empty message and undefined cause.
§Examples
let error = JsNativeError::eval();
assert!(matches!(error.kind(), JsNativeErrorKind::Eval));Sourcepub const fn is_eval(&self) -> bool
pub const fn is_eval(&self) -> bool
Check if it’s a JsNativeErrorKind::Eval.
Sourcepub const fn range() -> Self
pub const fn range() -> Self
Creates a new JsNativeError of kind RangeError, with empty message and undefined cause.
§Examples
let error = JsNativeError::range();
assert!(matches!(error.kind(), JsNativeErrorKind::Range));Sourcepub const fn is_range(&self) -> bool
pub const fn is_range(&self) -> bool
Check if it’s a JsNativeErrorKind::Range.
Sourcepub const fn reference() -> Self
pub const fn reference() -> Self
Creates a new JsNativeError of kind ReferenceError, with empty message and undefined cause.
§Examples
let error = JsNativeError::reference();
assert!(matches!(error.kind(), JsNativeErrorKind::Reference));Sourcepub const fn is_reference(&self) -> bool
pub const fn is_reference(&self) -> bool
Check if it’s a JsNativeErrorKind::Reference.
Sourcepub const fn syntax() -> Self
pub const fn syntax() -> Self
Creates a new JsNativeError of kind SyntaxError, with empty message and undefined cause.
§Examples
let error = JsNativeError::syntax();
assert!(matches!(error.kind(), JsNativeErrorKind::Syntax));Sourcepub const fn is_syntax(&self) -> bool
pub const fn is_syntax(&self) -> bool
Check if it’s a JsNativeErrorKind::Syntax.
Sourcepub const fn typ() -> Self
pub const fn typ() -> Self
Creates a new JsNativeError of kind TypeError, with empty message and undefined cause.
§Examples
let error = JsNativeError::typ();
assert!(matches!(error.kind(), JsNativeErrorKind::Type));Sourcepub const fn is_type(&self) -> bool
pub const fn is_type(&self) -> bool
Check if it’s a JsNativeErrorKind::Type.
Sourcepub const fn uri() -> Self
pub const fn uri() -> Self
Creates a new JsNativeError of kind UriError, with empty message and undefined cause.
§Examples
let error = JsNativeError::uri();
assert!(matches!(error.kind(), JsNativeErrorKind::Uri));Sourcepub const fn is_uri(&self) -> bool
pub const fn is_uri(&self) -> bool
Check if it’s a JsNativeErrorKind::Uri.
Sourcepub fn with_message<S>(self, message: S) -> Self
pub fn with_message<S>(self, message: S) -> Self
Sets the message of this error.
§Examples
let error = JsNativeError::range().with_message("number too large");
assert_eq!(error.message(), "number too large");Sourcepub fn with_cause<V>(self, cause: V) -> Self
pub fn with_cause<V>(self, cause: V) -> Self
Sourcepub fn message(&self) -> &str
pub fn message(&self) -> &str
Gets the message of this error.
This is equivalent to the NativeError.prototype.message
property.
§Examples
let error = JsNativeError::range().with_message("number too large");
assert_eq!(error.message(), "number too large");Sourcepub fn cause(&self) -> Option<&JsError>
pub fn cause(&self) -> Option<&JsError>
Gets the cause of this error.
This is equivalent to the NativeError.prototype.cause
property.
§Examples
let cause = JsNativeError::syntax();
let error = JsNativeError::error().with_cause(cause);
assert!(error.cause().unwrap().as_native().is_some());Sourcepub fn into_opaque(self, context: &mut Context) -> JsObject
pub fn into_opaque(self, context: &mut Context) -> JsObject
Converts this native error to its opaque representation as a JsObject.
§Examples
let context = &mut Context::default();
let error = JsNativeError::error().with_message("error!");
let error_obj = error.into_opaque(context);
assert!(error_obj.is::<Error>());
assert_eq!(
error_obj.get(js_string!("message"), context).unwrap(),
js_string!("error!").into()
)Trait Implementations§
Source§impl Clone for JsNativeError
impl Clone for JsNativeError
Source§fn clone(&self) -> JsNativeError
fn clone(&self) -> JsNativeError
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for JsNativeError
impl Debug for JsNativeError
Source§impl Display for JsNativeError
impl Display for JsNativeError
Source§impl Error for JsNativeError
impl Error for JsNativeError
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
use the Display impl or to_string()
Source§impl From<Error> for JsNativeError
impl From<Error> for JsNativeError
Source§impl From<IcuError> for JsNativeError
impl From<IcuError> for JsNativeError
Source§impl From<JsNativeError> for JsError
impl From<JsNativeError> for JsError
Source§fn from(error: JsNativeError) -> Self
fn from(error: JsNativeError) -> Self
Source§impl From<TemporalError> for JsNativeError
impl From<TemporalError> for JsNativeError
Source§fn from(value: TemporalError) -> Self
fn from(value: TemporalError) -> Self
Source§impl PartialEq for JsNativeError
impl PartialEq for JsNativeError
Source§impl Trace for JsNativeError
impl Trace for JsNativeError
Source§unsafe fn trace_non_roots(&self)
unsafe fn trace_non_roots(&self)
Source§fn run_finalizer(&self)
fn run_finalizer(&self)
Finalize::finalize on this object and all
contained subobjects.impl Eq for JsNativeError
impl StructuralPartialEq for JsNativeError
Auto Trait Implementations§
impl Freeze for JsNativeError
impl !RefUnwindSafe for JsNativeError
impl !Send for JsNativeError
impl !Sync for JsNativeError
impl Unpin for JsNativeError
impl UnsafeUnpin for JsNativeError
impl !UnwindSafe for JsNativeError
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.