workflow_wasm/
printable.rs1use wasm_bindgen::prelude::*;
6
7#[derive(Clone, Debug)]
11pub struct Printable(JsValue);
12
13unsafe impl Send for Printable {}
14unsafe impl Sync for Printable {}
15
16impl Printable {
17 pub fn new(value: JsValue) -> Self {
19 Self(value)
20 }
21}
22
23impl std::fmt::Display for Printable {
24 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25 if let Some(string) = self.0.as_string() {
26 write!(f, "{}", string)
27 } else {
28 write!(f, "{:?}", self.0)
29 }
30 }
31}
32
33impl AsRef<JsValue> for Printable {
34 fn as_ref(&self) -> &JsValue {
35 &self.0
36 }
37}
38
39impl From<JsValue> for Printable {
40 fn from(value: JsValue) -> Self {
41 Self(value)
42 }
43}
44
45impl From<JsError> for Printable {
46 fn from(value: JsError) -> Self {
47 Self(value.into())
48 }
49}
50
51impl From<&Printable> for JsValue {
52 fn from(value: &Printable) -> Self {
53 value.0.clone()
54 }
55}