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

Update serde derives. #56

Merged
merged 1 commit into from
Mar 6, 2024
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: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ edition = "2018"
targets = []

[features]
serialize = ["serde", "serde_derive"]
serialize = ["serde"]

[dependencies]
byteorder = "1.3.4"
Expand All @@ -25,8 +25,7 @@ enum_primitive = "0.1.1"
image = "0.24"
itertools = "0.11"
num = "0.4"
serde = { version = "1.*.*", optional = true }
serde_derive = { version = "1.*.*", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
uuid = { version = "1.3.3", features = ["serde", "v4"] }

[build-dependencies]
Expand Down
14 changes: 10 additions & 4 deletions build/entity_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use std::collections::HashSet;
use std::fs::File;
use std::io::{BufReader, Write};
use std::iter::Iterator;

Check warning on line 12 in build/entity_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 12 in build/entity_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 12 in build/entity_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 12 in build/entity_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 12 in build/entity_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 12 in build/entity_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 12 in build/entity_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 12 in build/entity_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest, nightly)

the item `Iterator` is imported redundantly
use std::path::Path;

pub fn generate_entities(generated_dir: &Path) {
Expand Down Expand Up @@ -66,7 +66,9 @@
panic!("Expected first entity to be 'Entity'.");
}
fun.push_str("#[derive(Debug, Clone)]\n");
fun.push_str("#[cfg_attr(feature = \"serialize\", derive(Serialize, Deserialize))]\n");
fun.push_str(
"#[cfg_attr(feature = \"serialize\", derive(serde::Serialize, serde::Deserialize))]\n",
);
fun.push_str("pub struct EntityCommon {\n");
for c in &entity.children {
let t = if allow_multiples(c) {
Expand Down Expand Up @@ -107,7 +109,9 @@
fun.push('\n');

fun.push_str("#[derive(Debug, Clone)]\n");
fun.push_str("#[cfg_attr(feature = \"serialize\", derive(Serialize, Deserialize))]\n");
fun.push_str(
"#[cfg_attr(feature = \"serialize\", derive(serde::Serialize, serde::Deserialize))]\n",
);
fun.push_str("pub struct Entity {\n");
fun.push_str(" pub common: EntityCommon,\n");
fun.push_str(" pub specific: EntityType,\n");
Expand Down Expand Up @@ -209,7 +213,9 @@

fn generate_entity_types(fun: &mut String, element: &Element) {
fun.push_str("#[derive(Clone, Debug, PartialEq)]\n");
fun.push_str("#[cfg_attr(feature = \"serialize\", derive(Serialize, Deserialize))]\n");
fun.push_str(
"#[cfg_attr(feature = \"serialize\", derive(serde::Serialize, serde::Deserialize))]\n",
);
fun.push_str("pub enum EntityType {\n");
for c in &element.children {
if c.name != "Entity" {
Expand All @@ -231,7 +237,7 @@
if name(c) != "Entity" {
// definition
fun.push_str("#[derive(Clone, Debug, PartialEq)]\n");
fun.push_str("#[cfg_attr(feature = \"serialize\", derive(Serialize, Deserialize))]\n");
fun.push_str("#[cfg_attr(feature = \"serialize\", derive(serde::Serialize, serde::Deserialize))]\n");
fun.push_str(&format!("pub struct {typ} {{\n", typ = name(c)));
if base_class(c) == "DimensionBase" {
fun.push_str(" pub dimension_base: DimensionBase,\n");
Expand Down
4 changes: 3 additions & 1 deletion build/header_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use std::collections::HashSet;
use std::fs::File;
use std::io::{BufReader, Write};
use std::iter::Iterator;

Check warning on line 12 in build/header_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 12 in build/header_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 12 in build/header_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 12 in build/header_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 12 in build/header_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 12 in build/header_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 12 in build/header_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 12 in build/header_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest, nightly)

the item `Iterator` is imported redundantly
use std::path::Path;

pub fn generate_header(generated_dir: &Path) {
Expand Down Expand Up @@ -60,7 +60,9 @@
fn generate_struct(fun: &mut String, element: &Element) {
let mut seen_fields = HashSet::new();
fun.push_str("/// Contains common properties for the DXF file.\n");
fun.push_str("#[cfg_attr(feature = \"serialize\", derive(Serialize, Deserialize))]\n");
fun.push_str(
"#[cfg_attr(feature = \"serialize\", derive(serde::Serialize, serde::Deserialize))]\n",
);
fun.push_str("pub struct Header {\n");
for v in &element.children {
let field_name = field(v);
Expand Down
14 changes: 10 additions & 4 deletions build/object_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use std::collections::HashSet;
use std::fs::File;
use std::io::{BufReader, Write};
use std::iter::Iterator;

Check warning on line 12 in build/object_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 12 in build/object_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 12 in build/object_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 12 in build/object_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 12 in build/object_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 12 in build/object_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 12 in build/object_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 12 in build/object_generator.rs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest, nightly)

the item `Iterator` is imported redundantly
use std::path::Path;

pub fn generate_objects(generated_dir: &Path) {
Expand Down Expand Up @@ -73,7 +73,9 @@
panic!("Expected first object to be 'Object'.");
}
fun.push_str("#[derive(Clone, Debug)]\n");
fun.push_str("#[cfg_attr(feature = \"serialize\", derive(Serialize, Deserialize))]\n");
fun.push_str(
"#[cfg_attr(feature = \"serialize\", derive(serde::Serialize, serde::Deserialize))]\n",
);
fun.push_str("pub struct ObjectCommon {\n");
for c in &object.children {
let t = if allow_multiples(c) {
Expand Down Expand Up @@ -114,7 +116,9 @@
fun.push('\n');

fun.push_str("#[derive(Clone, Debug)]\n");
fun.push_str("#[cfg_attr(feature = \"serialize\", derive(Serialize, Deserialize))]\n");
fun.push_str(
"#[cfg_attr(feature = \"serialize\", derive(serde::Serialize, serde::Deserialize))]\n",
);
fun.push_str("pub struct Object {\n");
fun.push_str(" pub common: ObjectCommon,\n");
fun.push_str(" pub specific: ObjectType,\n");
Expand Down Expand Up @@ -219,7 +223,9 @@
fn generate_object_types(fun: &mut String, element: &Element) {
fun.push_str("#[allow(clippy::large_enum_variant)]\n");
fun.push_str("#[derive(Clone, Debug, PartialEq)]\n");
fun.push_str("#[cfg_attr(feature = \"serialize\", derive(Serialize, Deserialize))]\n");
fun.push_str(
"#[cfg_attr(feature = \"serialize\", derive(serde::Serialize, serde::Deserialize))]\n",
);
fun.push_str("pub enum ObjectType {\n");
for c in &element.children {
if c.name != "Object" {
Expand All @@ -241,7 +247,7 @@
if name(c) != "Object" {
// definition
fun.push_str("#[derive(Clone, Debug, PartialEq)]\n");
fun.push_str("#[cfg_attr(feature = \"serialize\", derive(Serialize, Deserialize))]\n");
fun.push_str("#[cfg_attr(feature = \"serialize\", derive(serde::Serialize, serde::Deserialize))]\n");
fun.push_str(&format!("pub struct {typ} {{\n", typ = name(c)));
for f in &c.children {
let t = if allow_multiples(f) {
Expand Down
4 changes: 3 additions & 1 deletion build/table_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ fn generate_table_items(fun: &mut String, element: &Element) {
let mut seen_fields = HashSet::new();
let table_item = &table.children[0];
fun.push_str("#[derive(Debug)]\n");
fun.push_str("#[cfg_attr(feature = \"serialize\", derive(Serialize, Deserialize))]\n");
fun.push_str(
"#[cfg_attr(feature = \"serialize\", derive(serde::Serialize, serde::Deserialize))]\n",
);
fun.push_str(&format!("pub struct {name} {{\n", name = name(table_item)));
fun.push_str(" pub name: String,\n");
fun.push_str(" pub handle: Handle,\n");
Expand Down
2 changes: 1 addition & 1 deletion src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::x_data;

/// A block is a collection of entities.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
pub struct Block {
/// The block's handle.
pub handle: Handle,
Expand Down
2 changes: 1 addition & 1 deletion src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::helper_functions::*;

/// Represents an application-defined class whose instances are `Block`s, `Entity`s, and `Object`s.
#[derive(Clone)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
pub struct Class {
/// Class DXF record name.
pub record_name: String,
Expand Down
2 changes: 1 addition & 1 deletion src/code_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::helper_functions::parse_hex_string;
/// The basic primitive of a DXF file; a code indicating the type of the data contained, and the
/// data itself.
#[derive(Clone)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
pub struct CodePair {
pub code: i32,
pub value: CodePairValue,
Expand Down
2 changes: 1 addition & 1 deletion src/code_pair_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fmt::{Debug, Display, Formatter};

/// Contains the data portion of a `CodePair`.
#[derive(PartialEq)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
pub enum CodePairValue {
Boolean(i16),
Integer(i32),
Expand Down
2 changes: 1 addition & 1 deletion src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::tables::Layer;

/// Represents an indexed color.
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
pub struct Color {
raw_value: i16,
}
Expand Down
2 changes: 1 addition & 1 deletion src/data_table_value.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{Handle, Point};

#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
pub enum DataTableValue {
Boolean(bool),
Integer(i32),
Expand Down
2 changes: 1 addition & 1 deletion src/drawing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@

use itertools::put_back;
use std::collections::HashSet;
use std::iter::Iterator;

Check warning on line 36 in src/drawing.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 36 in src/drawing.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 36 in src/drawing.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 36 in src/drawing.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 36 in src/drawing.rs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 36 in src/drawing.rs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 36 in src/drawing.rs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest, nightly)

the item `Iterator` is imported redundantly

Check warning on line 36 in src/drawing.rs

View workflow job for this annotation

GitHub Actions / Build and test (windows-latest, nightly)

the item `Iterator` is imported redundantly
use std::path::Path;

pub(crate) const AUTO_REPLACE_HANDLE: Handle = Handle(0xFFFF_FFFF_FFFF_FFFF);

/// Represents a DXF drawing.
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
pub struct Drawing {
/// The drawing's header. Contains various drawing-specific values and settings.
pub header: Header,
Expand Down
2 changes: 1 addition & 1 deletion src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl Line {
//------------------------------------------------------------------------------
/// Represents a single vertex of a `LwPolyline`.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
pub struct LwPolylineVertex {
pub x: f64,
pub y: f64,
Expand Down
Loading
Loading