aboutsummaryrefslogtreecommitdiffstats
path: root/components/style_traits/owned_slice.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/style_traits/owned_slice.rs')
-rw-r--r--components/style_traits/owned_slice.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/components/style_traits/owned_slice.rs b/components/style_traits/owned_slice.rs
index 33d3ac1c2ab..bbce7065196 100644
--- a/components/style_traits/owned_slice.rs
+++ b/components/style_traits/owned_slice.rs
@@ -7,6 +7,8 @@
//! A replacement for `Box<[T]>` that cbindgen can understand.
use malloc_size_of::{MallocShallowSizeOf, MallocSizeOf, MallocSizeOfOps};
+use serde::de::{Deserialize, Deserializer};
+use serde::ser::{Serialize, Serializer};
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
use std::ptr::NonNull;
@@ -171,3 +173,22 @@ impl<T> iter::FromIterator<T> for OwnedSlice<T> {
Vec::from_iter(iter).into()
}
}
+
+impl<T: Serialize> Serialize for OwnedSlice<T> {
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: Serializer,
+ {
+ self.deref().serialize(serializer)
+ }
+}
+
+impl<'de, T: Deserialize<'de>> Deserialize<'de> for OwnedSlice<T> {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: Deserializer<'de>,
+ {
+ let r = Box::<[T]>::deserialize(deserializer)?;
+ Ok(r.into())
+ }
+}