Struct rquickjs_core::Coerced [−][src]
#[repr(transparent)]pub struct Coerced<T>(pub T);
Expand description
The wrapper for values to force coercion
// Coercion to string
assert_eq!(ctx.eval::<Coerced<String>, _>("`abc`")?.0, "abc");
assert_eq!(ctx.eval::<Coerced<String>, _>("123")?.0, "123");
assert_eq!(ctx.eval::<Coerced<String>, _>("[1,'a']")?.0, "1,a");
assert_eq!(ctx.eval::<Coerced<String>, _>("({})")?.0, "[object Object]");
// Coercion to integer
assert!(ctx.eval::<i32, _>("123.5").is_err());
assert_eq!(ctx.eval::<Coerced<i32>, _>("123.5")?.0, 123);
assert!(ctx.eval::<i32, _>("`123`").is_err());
assert_eq!(ctx.eval::<Coerced<i32>, _>("`123`")?.0, 123);
// Coercion to floating-point
assert_eq!(ctx.eval::<f64, _>("123")?, 123.0);
assert_eq!(ctx.eval::<Coerced<f64>, _>("123")?.0, 123.0);
assert!(ctx.eval::<f64, _>("`123.5`").is_err());
assert_eq!(ctx.eval::<Coerced<f64>, _>("`123.5`")?.0, 123.5);
Tuple Fields
0: T
Trait Implementations
Coerce a value to a string in the same way javascript would coerce values.
Coerce a value to a string in the same way javascript would coerce values.
Coerce a value to a i32
in the same way javascript would coerce values
Coerce a value to a i64
in the same way javascript would coerce values
Coerce a value to a u64
in the same way javascript would coerce values
Coerce a value to a f64
in the same way javascript would coerce values
Coerce a value to a bool
in the same way javascript would coerce values
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for Coerced<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Coerced<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.