Skip to content

Commit

Permalink
Derive Serialize and Deserialize for CSS Grid types used in Style (#363)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
James Higgins and nicoburns authored Feb 12, 2023
1 parent 868b3a4 commit 1d952bb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/compute/grid/types/coordinates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/style/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 1d952bb

Please sign in to comment.