Struct rquickjs::Coerced [−][src]
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 for Coerced<T> where
T: Clone,
[src]
T: Clone,
impl<T> Copy for Coerced<T> where
T: Copy,
[src]
T: Copy,
impl<T> Debug for Coerced<T> where
T: Debug,
[src]
T: Debug,
impl<T> Deref for Coerced<T>
[src]
type Target = T
The resulting type after dereferencing.
pub fn deref(&self) -> &<Coerced<T> as Deref>::Target
[src]
impl<T> DerefMut for Coerced<T>
[src]
impl<T> Eq for Coerced<T> where
T: Eq,
[src]
T: Eq,
impl<'js> FromJs<'js> for Coerced<bool>
[src]
Coerce a value to a bool
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<f64>
[src]
Coerce a value to a f64
in the same way javascript would coerce values
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<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<String>
[src]
Coerce a value to a string in the same way javascript would coerce values.
impl<T> Hash for Coerced<T> where
T: Hash,
[src]
T: Hash,
pub fn hash<__H>(&self, state: &mut __H) where
__H: Hasher,
[src]
__H: Hasher,
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T> Ord for Coerced<T> where
T: Ord,
[src]
T: Ord,
pub fn cmp(&self, other: &Coerced<T>) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<T> PartialEq<Coerced<T>> for Coerced<T> where
T: PartialEq<T>,
[src]
T: PartialEq<T>,
impl<T> PartialOrd<Coerced<T>> for Coerced<T> where
T: PartialOrd<T>,
[src]
T: PartialOrd<T>,
pub fn partial_cmp(&self, other: &Coerced<T>) -> Option<Ordering>
[src]
pub fn lt(&self, other: &Coerced<T>) -> bool
[src]
pub fn le(&self, other: &Coerced<T>) -> bool
[src]
pub fn gt(&self, other: &Coerced<T>) -> bool
[src]
pub fn ge(&self, other: &Coerced<T>) -> bool
[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]
T: RefUnwindSafe,
impl<T> Send for Coerced<T> where
T: Send,
[src]
T: Send,
impl<T> Sync for Coerced<T> where
T: Sync,
[src]
T: Sync,
impl<T> Unpin for Coerced<T> where
T: Unpin,
[src]
T: Unpin,
impl<T> UnwindSafe for Coerced<T> where
T: UnwindSafe,
[src]
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
pub fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ParallelSend for T where
T: Send,
[src]
T: Send,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,