ToJsValue

Trait ToJsValue 

Source
pub trait ToJsValue {
    // Required method
    fn to_js_value(&self) -> String;
}
Expand description

A trait for converting Rust types to JavaScript value representations.

Types that implement this trait can be used in js! macro interpolation.

§Examples

use viewpoint_js_core::ToJsValue;

assert_eq!(42.to_js_value(), "42");
assert_eq!(true.to_js_value(), "true");
assert_eq!("hello".to_js_value(), r#""hello""#);

Required Methods§

Source

fn to_js_value(&self) -> String

Convert this value to a JavaScript representation.

The returned string should be valid JavaScript that represents this value. For example:

  • Integers: "42"
  • Strings: "\"hello\""
  • Booleans: "true" or "false"
  • null: "null"

Implementations on Foreign Types§

Source§

impl ToJsValue for bool

Source§

impl ToJsValue for f32

Source§

impl ToJsValue for f64

Source§

impl ToJsValue for i8

Source§

impl ToJsValue for i16

Source§

impl ToJsValue for i32

Source§

impl ToJsValue for i64

Source§

impl ToJsValue for i128

Source§

impl ToJsValue for isize

Source§

impl ToJsValue for str

Source§

impl ToJsValue for u8

Source§

impl ToJsValue for u16

Source§

impl ToJsValue for u32

Source§

impl ToJsValue for u64

Source§

impl ToJsValue for u128

Source§

impl ToJsValue for usize

Source§

impl ToJsValue for String

Source§

impl<T: ToJsValue + ?Sized> ToJsValue for &T

Source§

impl<T: ToJsValue + ?Sized> ToJsValue for &mut T

Source§

impl<T: ToJsValue + ?Sized> ToJsValue for Box<T>

Source§

impl<T: ToJsValue> ToJsValue for Option<T>

Implementors§