Struct rquickjs_core::Coerced[][src]

#[repr(transparent)]pub struct Coerced<T>(pub T);

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);

Trait Implementations

impl<T> AsMut<T> for Coerced<T>[src]

impl<T> AsRef<T> for Coerced<T>[src]

impl<T: Clone> Clone for Coerced<T>[src]

impl<T: Copy> Copy for Coerced<T>[src]

impl<T: Debug> Debug for Coerced<T>[src]

impl<T> Deref for Coerced<T>[src]

type Target = T

The resulting type after dereferencing.

impl<T> DerefMut for Coerced<T>[src]

impl<T: Eq> Eq for Coerced<T>[src]

impl<'js> FromJs<'js> for Coerced<String<'js>>[src]

Coerce a value to a string in the same way javascript would coerce values.

impl<'js> FromJs<'js> for Coerced<StdString>[src]

Coerce a value to a string in the same way javascript would coerce values.

impl<'js> FromJs<'js> for Coerced<i32>[src]

Coerce a value to a i32 in the same way javascript would coerce values

impl<'js> FromJs<'js> for Coerced<i64>[src]

Coerce a value to a i64 in the same way javascript would coerce values

impl<'js> FromJs<'js> for Coerced<u64>[src]

Coerce a value to a u64 in the same way javascript would coerce values

impl<'js> FromJs<'js> for Coerced<f64>[src]

Coerce a value to a f64 in the same way javascript would coerce values

impl<'js> FromJs<'js> for Coerced<bool>[src]

Coerce a value to a bool in the same way javascript would coerce values

impl<T: Hash> Hash for Coerced<T>[src]

impl<T: Ord> Ord for Coerced<T>[src]

impl<T: PartialEq> PartialEq<Coerced<T>> for Coerced<T>[src]

impl<T: PartialOrd> PartialOrd<Coerced<T>> for Coerced<T>[src]

impl<T> StructuralEq for Coerced<T>[src]

impl<T> StructuralPartialEq for Coerced<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Coerced<T> where
    T: RefUnwindSafe
[src]

impl<T> Send for Coerced<T> where
    T: Send
[src]

impl<T> Sync for Coerced<T> where
    T: Sync
[src]

impl<T> Unpin for Coerced<T> where
    T: Unpin
[src]

impl<T> UnwindSafe for Coerced<T> where
    T: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.