[go: up one dir, main page]

worker/
version.rs

1use crate::EnvBinding;
2use wasm_bindgen::{JsCast, JsValue};
3use worker_sys::types::CfVersionMetadata;
4
5#[derive(Debug)]
6pub struct WorkerVersionMetadata(CfVersionMetadata);
7
8unsafe impl Send for WorkerVersionMetadata {}
9unsafe impl Sync for WorkerVersionMetadata {}
10
11impl EnvBinding for WorkerVersionMetadata {
12    const TYPE_NAME: &'static str = "Object";
13}
14
15impl WorkerVersionMetadata {
16    pub fn id(&self) -> String {
17        self.0.id()
18    }
19
20    pub fn tag(&self) -> String {
21        self.0.tag()
22    }
23
24    pub fn timestamp(&self) -> String {
25        self.0.timestamp()
26    }
27}
28
29impl JsCast for WorkerVersionMetadata {
30    fn instanceof(val: &JsValue) -> bool {
31        val.is_instance_of::<CfVersionMetadata>()
32    }
33
34    fn unchecked_from_js(val: JsValue) -> Self {
35        Self(val.into())
36    }
37
38    fn unchecked_from_js_ref(val: &JsValue) -> &Self {
39        unsafe { &*(val as *const JsValue as *const Self) }
40    }
41}
42
43impl From<WorkerVersionMetadata> for JsValue {
44    fn from(cf_version: WorkerVersionMetadata) -> Self {
45        JsValue::from(cf_version.0)
46    }
47}
48
49impl AsRef<JsValue> for WorkerVersionMetadata {
50    fn as_ref(&self) -> &JsValue {
51        &self.0
52    }
53}