Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove explicit serialization feature from fj; leave implicit serde feature #688

Merged
merged 2 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions crates/fj/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ license = "0BSD"
keywords = ["cad", "programmatic", "code-cad"]
categories = ["encoding", "mathematics", "rendering"]

[features]
default = []
serialization = ["serde"]

[dependencies]
serde = { version = "1.0.7", features = ["derive"], optional = true }
Expand All @@ -22,4 +19,4 @@ serde = { version = "1.0.7", features = ["derive"], optional = true }
path = "../../crates/fj-proc"

[dev-dependencies]
serde_json = "1.0.81"
serde_json = "1.0.81"
4 changes: 2 additions & 2 deletions crates/fj/src/angle.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(feature = "serialization")]
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::f64::consts::{PI, TAU};

Expand All @@ -7,7 +7,7 @@ const GON_RAD: f64 = PI / 200.;

/// An angle
#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Angle {
// The value of the angle in radians
rad: f64,
Expand Down
4 changes: 2 additions & 2 deletions crates/fj/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ mod shape_3d;

pub use self::{angle::*, shape_2d::*, shape_3d::*};
pub use fj_proc::*;
#[cfg(feature = "serialization")]
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// A shape
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(C)]
pub enum Shape {
/// A 2D shape
Expand Down
16 changes: 8 additions & 8 deletions crates/fj/src/shape_2d.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(feature = "serialization")]
#[cfg(feature = "serde")]
use serde::{de, ser, Deserialize, Serialize};
use std::mem;
use std::sync::atomic;
Expand All @@ -7,7 +7,7 @@ use crate::Shape;

/// A 2-dimensional shape
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(C)]
pub enum Shape2d {
/// A circle
Expand All @@ -33,7 +33,7 @@ impl Shape2d {

/// A circle
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(C)]
pub struct Circle {
/// The radius of the circle
Expand Down Expand Up @@ -87,7 +87,7 @@ impl From<Circle> for Shape2d {

/// A difference between two shapes
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(C)]
pub struct Difference2d {
shapes: [Shape2d; 2],
Expand Down Expand Up @@ -260,15 +260,15 @@ impl Drop for Sketch {
/// Note that constructing this requires cloning the points behind Sketch. If
/// de/serialization turns out to be a bottleneck, a more complete implementation
/// will be required.
#[cfg(feature = "serialization")]
#[cfg(feature = "serde")]
#[derive(Serialize, Deserialize)]
#[serde(rename = "Sketch")]
struct SerdeSketch {
points: Vec<[f64; 2]>,
color: [u8; 4],
}

#[cfg(feature = "serialization")]
#[cfg(feature = "serde")]
impl ser::Serialize for Sketch {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand All @@ -283,7 +283,7 @@ impl ser::Serialize for Sketch {
}
}

#[cfg(feature = "serialization")]
#[cfg(feature = "serde")]
impl<'de> de::Deserialize<'de> for Sketch {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
Expand Down Expand Up @@ -353,7 +353,7 @@ mod tests {
// rc is deallocated after the last drop, so we can't assert that it's 0
}

#[cfg(feature = "serialization")]
#[cfg(feature = "serde")]
#[test]
fn test_serialize_loopback() {
use serde_json::{from_str, to_string};
Expand Down
10 changes: 5 additions & 5 deletions crates/fj/src/shape_3d.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{Angle, Shape, Shape2d};
#[cfg(feature = "serialization")]
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// A 3-dimensional shape
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(C)]
pub enum Shape3d {
/// A group of two 3-dimensional shapes
Expand Down Expand Up @@ -32,7 +32,7 @@ impl From<Shape3d> for Shape {
///
/// Whether the shapes in the group touch or overlap is not currently checked.
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(C)]
pub struct Group {
/// The first of the shapes
Expand Down Expand Up @@ -64,7 +64,7 @@ impl From<Group> for Shape3d {
/// See issue:
/// <https://github.com/hannobraun/Fornjot/issues/101>
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(C)]
pub struct Transform {
/// The shape being transformed
Expand Down Expand Up @@ -94,7 +94,7 @@ impl From<Transform> for Shape3d {

/// A sweep of a 2-dimensional shape along straight path
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(C)]
pub struct Sweep {
/// The 2-dimensional shape being swept
Expand Down