script/dom/bindings/
serializable.rs1use script_bindings::serializable::Serializable;
9use servo_base::id::{Index, NamespaceIndex, PipelineNamespaceId};
10
11#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
14pub(crate) struct StorageKey {
15 pub(crate) index: u32,
16 pub(crate) name_space: u32,
17}
18
19impl StorageKey {
20 pub(crate) fn new<T>(index: NamespaceIndex<T>) -> StorageKey {
21 let name_space = index.namespace_id.0.to_ne_bytes();
22 let index = index.index.0.get().to_ne_bytes();
23 StorageKey {
24 index: u32::from_ne_bytes(index),
25 name_space: u32::from_ne_bytes(name_space),
26 }
27 }
28}
29
30impl<T> From<StorageKey> for NamespaceIndex<T> {
31 fn from(key: StorageKey) -> NamespaceIndex<T> {
32 NamespaceIndex {
33 namespace_id: PipelineNamespaceId(key.name_space),
34 index: Index::new(key.index).expect("Index must not be zero"),
35 }
36 }
37}
38
39pub(crate) fn assert_serializable<T: Serializable<crate::DomTypeHolder>>() {}