[go: up one dir, main page]

worker/
version.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use crate::EnvBinding;
use wasm_bindgen::{JsCast, JsValue};
use worker_sys::types::CfVersionMetadata;

pub struct WorkerVersionMetadata(CfVersionMetadata);

unsafe impl Send for WorkerVersionMetadata {}
unsafe impl Sync for WorkerVersionMetadata {}

impl EnvBinding for WorkerVersionMetadata {
    const TYPE_NAME: &'static str = "Object";
}

impl WorkerVersionMetadata {
    pub fn id(&self) -> String {
        self.0.id()
    }

    pub fn tag(&self) -> String {
        self.0.tag()
    }

    pub fn timestamp(&self) -> String {
        self.0.timestamp()
    }
}

impl JsCast for WorkerVersionMetadata {
    fn instanceof(val: &JsValue) -> bool {
        val.is_instance_of::<CfVersionMetadata>()
    }

    fn unchecked_from_js(val: JsValue) -> Self {
        Self(val.into())
    }

    fn unchecked_from_js_ref(val: &JsValue) -> &Self {
        unsafe { &*(val as *const JsValue as *const Self) }
    }
}

impl From<WorkerVersionMetadata> for JsValue {
    fn from(cf_version: WorkerVersionMetadata) -> Self {
        JsValue::from(cf_version.0)
    }
}

impl AsRef<JsValue> for WorkerVersionMetadata {
    fn as_ref(&self) -> &JsValue {
        &self.0
    }
}