Skip to content

Commit

Permalink
style: Use Serde for SVGOffsetPath.
Browse files Browse the repository at this point in the history
  • Loading branch information
BorisChiou authored and emilio committed Feb 12, 2020
1 parent 5ac08e4 commit 2b3ef3f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
3 changes: 3 additions & 0 deletions components/style/values/generics/motion.rs
Expand Up @@ -73,13 +73,16 @@ pub struct RayFunction<Angle> {
/// The offset-path value.
///
/// https://drafts.fxtf.org/motion-1/#offset-path-property
/// cbindgen:private-default-tagged-enum-constructor=false
#[derive(
Animate,
Clone,
ComputeSquaredDistance,
Debug,
Deserialize,
MallocSizeOf,
PartialEq,
Serialize,
SpecifiedValueInfo,
ToAnimatedZero,
ToComputedValue,
Expand Down
12 changes: 11 additions & 1 deletion components/style/values/specified/svg_path.rs
Expand Up @@ -21,8 +21,10 @@ use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
#[derive(
Clone,
Debug,
Deserialize,
MallocSizeOf,
PartialEq,
Serialize,
SpecifiedValueInfo,
ToAnimatedZero,
ToComputedValue,
Expand Down Expand Up @@ -156,8 +158,10 @@ impl ComputeSquaredDistance for SVGPathData {
ComputeSquaredDistance,
Copy,
Debug,
Deserialize,
MallocSizeOf,
PartialEq,
Serialize,
SpecifiedValueInfo,
ToAnimatedZero,
ToShmem,
Expand Down Expand Up @@ -483,8 +487,10 @@ impl ToCss for PathCommand {
ComputeSquaredDistance,
Copy,
Debug,
Deserialize,
MallocSizeOf,
PartialEq,
Serialize,
SpecifiedValueInfo,
ToAnimatedZero,
ToShmem,
Expand All @@ -511,8 +517,10 @@ impl IsAbsolute {
ComputeSquaredDistance,
Copy,
Debug,
Deserialize,
MallocSizeOf,
PartialEq,
Serialize,
SpecifiedValueInfo,
ToAnimatedZero,
ToCss,
Expand All @@ -530,7 +538,9 @@ impl CoordPair {
}

/// The EllipticalArc flag type.
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToShmem)]
#[derive(
Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize, SpecifiedValueInfo, ToShmem,
)]
#[repr(C)]
pub struct ArcFlag(bool);

Expand Down
21 changes: 21 additions & 0 deletions components/style_traits/arc_slice.rs
Expand Up @@ -4,6 +4,8 @@

//! A thin atomically-reference-counted slice.

use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer};
use servo_arc::ThinArc;
use std::ops::Deref;
use std::ptr::NonNull;
Expand Down Expand Up @@ -60,6 +62,25 @@ impl<T> Default for ArcSlice<T> {
}
}

impl<T: Serialize> Serialize for ArcSlice<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 ArcSlice<T> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let r = Vec::deserialize(deserializer)?;
Ok(ArcSlice::from_iter(r.into_iter()))
}
}

impl<T> ArcSlice<T> {
/// Creates an Arc for a slice using the given iterator to generate the
/// slice.
Expand Down

0 comments on commit 2b3ef3f

Please sign in to comment.