Derive Serialize and Deserialize for CSS Grid types used in Style (#363)
* Derive Serialize and Deserialize for CSS Grid types when the serde feature flag is enabled * Remove Default implementation and serde(default) attributes * Add CI job for serde feature (with default features) * Re-add serde(default) attribute to Style --------- Co-authored-by: Nico Burns <nico@nicoburns.com>
Delta semántico
Ninguna definición cambió: el cambio es de texto, documentación o datos.
4 archivos · +21 −2
- .github/workflows/ci.yml +15 −0
- src/compute/grid/types/coordinates.rs +1 −0
- src/geometry.rs +1 −2
- src/style/grid.rs +4 −0
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index d6bbf0ce6..2fc108e47 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -37,6 +37,21 @@ jobs:
with:
command: test
+ test-features-default-with-serde:
+ name: "Test Suite [Features: Default + serde]"
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions-rs/toolchain@v1
+ with:
+ profile: minimal
+ toolchain: stable
+ override: true
+ - uses: actions-rs/cargo@v1
+ with:
+ command: test
+ args: --features serde
+
test-features-alloc:
name: "Test Suite [Features: alloc]"
runs-on: ubuntu-latest
diff --git a/src/compute/grid/types/coordinates.rs b/src/compute/grid/types/coordinates.rs
index 62525a8b6..cc8404ecb 100644
--- a/src/compute/grid/types/coordinates.rs
+++ b/src/compute/grid/types/coordinates.rs
@@ -13,6 +13,7 @@ use core::ops::{Add, AddAssign, Sub};
/// (and counts down from there)
/// - 0 is not a valid index
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(transparent)]
pub struct GridLine(i16);
diff --git a/src/geometry.rs b/src/geometry.rs
index 942cdd479..3db779ed1 100644
--- a/src/geometry.rs
+++ b/src/geometry.rs
@@ -10,7 +10,6 @@ use crate::axis::AbstractAxis;
/// An axis-aligned UI rectangle
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-#[cfg_attr(feature = "serde", serde(default))]
pub struct Rect<T> {
/// This can represent either the x-coordinate of the starting edge,
/// or the amount of padding on the starting side.
@@ -241,7 +240,6 @@ impl<T: Add + Copy> Line<T> {
/// The width and height of a [`Rect`]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-#[cfg_attr(feature = "serde", serde(default))]
pub struct Size<T> {
/// The x extent of the rectangle
pub width: T,
@@ -457,6 +455,7 @@ impl Point<Option<f32>> {
/// Generic struct which holds a "min" value and a "max" value
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct MinMax<Min, Max> {
/// The value representing the minimum
pub min: Min,
diff --git a/src/style/grid.rs b/src/style/grid.rs
index 4e84589d5..1053f74ff 100644
--- a/src/style/grid.rs
+++ b/src/style/grid.rs
@@ -238,6 +238,7 @@ impl Default for Line<GridPlacement> {
/// on the size of it's contents, the amount of available space, and the sizing constraint the grid is being size under.
/// See <https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-columns>
#[derive(Copy, Clone, PartialEq, Debug)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum MaxTrackSizingFunction {
/// Track maximum size should be a fixed points or percentage value
Fixed(LengthPercentage),
@@ -362,6 +363,7 @@ impl MaxTrackSizingFunction {
/// on the size of it's contents, the amount of available space, and the sizing constraint the grid is being size under.
/// See <https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-columns>
#[derive(Copy, Clone, PartialEq, Debug)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum MinTrackSizingFunction {
/// Track minimum size should be a fixed points or percentage value
Fixed(LengthPercentage),
@@ -492,6 +494,7 @@ impl FromFlex for NonRepeatedTrackSizingFunction {
/// See <https://www.w3.org/TR/css-grid-1/#auto-repeat> for an explanation of how auto-repeated track definitions work
/// and the difference between AutoFit and AutoFill.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum GridTrackRepetition {
/// Auto-repeating tracks should be generated to fit the container
/// See: <https://developer.mozilla.org/en-US/docs/Web/CSS/repeat#auto-fill>
@@ -534,6 +537,7 @@ impl<'a> TryFrom<&'a str> for GridTrackRepetition {
/// The sizing function for a grid track (row/column)
/// See <https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-columns>
#[derive(Clone, PartialEq, Debug)]
+#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum TrackSizingFunction {
/// A single non-repeated track
Single(NonRepeatedTrackSizingFunction),