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

Add serde serialization to fj. #610

Merged
merged 4 commits into from
May 20, 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
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions crates/fj/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ repository = "https://github.com/hannobraun/fornjot"
license = "0BSD"
keywords = ["cad", "programmatic", "code-cad"]
categories = ["encoding", "mathematics", "rendering"]

[features]
default = []
serialization = ["serde"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need an explicit feature here. Just having the implicit serde feature should be enough, and is what I've seen in other crates in the Rust ecosystem.


[dependencies]
serde = { version = "1.0.7", optional = true }
1 change: 1 addition & 0 deletions crates/fj/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub use self::{shape_2d::*, shape_3d::*};

/// A shape
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
#[repr(C)]
pub enum Shape {
/// A 2D shape
Expand Down
4 changes: 4 additions & 0 deletions crates/fj/src/shape_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::Shape;

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

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

/// A difference between two shapes
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
#[repr(C)]
pub struct Difference2d {
shapes: [Shape2d; 2],
Expand Down Expand Up @@ -126,6 +129,7 @@ impl From<Difference2d> for Shape2d {
/// that the edges are non-overlapping. If you create a `Sketch` with
/// overlapping edges, you're on your own.
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
#[repr(C)]
pub struct Sketch {
// The fields are the raw parts of a `Vec`. `Sketch` needs to be FFI-safe,
Expand Down
4 changes: 4 additions & 0 deletions crates/fj/src/shape_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{Shape, Shape2d};

/// A 3-dimensional shape
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
#[repr(C)]
pub enum Shape3d {
/// A group of two 3-dimensional shapes
Expand Down Expand Up @@ -29,6 +30,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))]
#[repr(C)]
pub struct Group {
/// The first of the shapes
Expand Down Expand Up @@ -60,6 +62,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))]
#[repr(C)]
pub struct Transform {
/// The shape being transformed
Expand Down Expand Up @@ -89,6 +92,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))]
#[repr(C)]
pub struct Sweep {
/// The 2-dimensional shape being swept
Expand Down