Skip to content

Commit 20e7848

Browse files
committed
feat: add serde feature
1 parent 72e073f commit 20e7848

25 files changed

+395
-19
lines changed

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"rust-analyzer.cargo.features": "all"
3+
}

Cargo.lock

+27-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kicad_format/Cargo.toml

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "kicad_format"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2021"
55
description = "A library for parsing KiCad 7.10 files into a more data driven representation"
66
authors = ["Adrian Wowk <adrian@adom.inc>"]
@@ -9,9 +9,15 @@ license = "MIT"
99
[dependencies]
1010
kicad_sexpr = { path = "../kicad_sexpr" }
1111
regex = "1.10.3"
12+
serde = { version = "1.0.130", features = ["derive"], optional = true }
1213
thiserror = "1.0.56"
13-
uuid = { version = "1.7.0", features = ["v4", "fast-rng"] }
14+
uuid = { version = "1.8.0", features = ["v4", "fast-rng"] }
15+
1416

1517
[dev-dependencies]
1618
ansi_term = "0.12.1"
1719
diff = "0.1.13"
20+
21+
22+
[features]
23+
serde = ["dep:serde", "uuid/serde"]

kicad_format/src/common/footprint/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ pub mod text;
2626
/// A footprint inlined within a PCB file.
2727
///
2828
/// TODO: move to pcb module
29+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
30+
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
2931
#[derive(Debug, PartialEq, Clone)]
3032
pub struct FootprintInlined {
3133
pub library_link: LibraryId,
@@ -299,6 +301,8 @@ impl ToSexpr for FootprintInlined {
299301
// ############################################################################
300302

301303
/// How pads are covered by copper in Zone
304+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
305+
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
302306
#[derive(Debug, PartialEq, Clone, Copy)]
303307
#[repr(u8)]
304308
pub enum ZoneConnectKind {
@@ -331,6 +335,8 @@ impl TryFrom<u8> for ZoneConnectKind {
331335
// ############################################################################
332336

333337
/// Attributes of the footprint (ex. SMD, through-hole, included in BOM, etc.)
338+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
339+
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
334340
#[derive(Debug, PartialEq, Default, Clone)]
335341
pub struct FootprintAttributes {
336342
pub smd: bool,
@@ -395,6 +401,9 @@ impl ToSexpr for FootprintAttributes {
395401

396402
/// All the types of graphics items that can be part of a footprint (images,
397403
/// text, text boxes, shapes, etc.)
404+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
405+
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
406+
#[cfg_attr(feature = "serde", serde(tag = "type"))]
398407
#[derive(Debug, PartialEq, Clone)]
399408
pub enum FootprintGraphicsItem {
400409
Image(Image),
@@ -462,6 +471,8 @@ impl ToSexpr for FootprintGraphicsItem {
462471
// ############################################################################
463472

464473
/// A 3D model associated with a footprint.
474+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
475+
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
465476
#[derive(Debug, PartialEq, Clone)]
466477
pub struct Model {
467478
pub file: String,

kicad_format/src/common/footprint/shape.rs

+17
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use crate::{
99
};
1010

1111
/// Common properties shared by the different shapes.
12+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
13+
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
1214
#[derive(Debug, PartialEq, Clone)]
1315
pub struct FootprintShape {
1416
pub locked: bool,
@@ -19,6 +21,9 @@ pub struct FootprintShape {
1921
}
2022

2123
/// All the different types of shapes allowed within a footprint.
24+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
25+
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
26+
#[cfg_attr(feature = "serde", serde(tag = "type"))]
2227
#[derive(Debug, PartialEq, Clone)]
2328
pub enum FootprintShapeKind {
2429
Line(FootprintLine),
@@ -221,39 +226,51 @@ impl ToSexpr for FootprintShape {
221226
}
222227
}
223228

229+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
230+
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
224231
#[derive(Debug, PartialEq, Clone)]
225232
pub struct FootprintLine {
226233
pub start: Vec2D,
227234
pub end: Vec2D,
228235
}
229236

237+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
238+
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
230239
#[derive(Debug, PartialEq, Clone)]
231240
pub struct FootprintRectangle {
232241
pub start: Vec2D,
233242
pub end: Vec2D,
234243
pub fill: SimpleFillMode,
235244
}
236245

246+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
247+
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
237248
#[derive(Debug, PartialEq, Clone)]
238249
pub struct FootprintCircle {
239250
pub center: Vec2D,
240251
pub end: Vec2D,
241252
pub fill: SimpleFillMode,
242253
}
243254

255+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
256+
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
244257
#[derive(Debug, PartialEq, Clone)]
245258
pub struct FootprintArc {
246259
pub start: Vec2D,
247260
pub midpoint: Vec2D,
248261
pub end: Vec2D,
249262
}
250263

264+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
265+
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
251266
#[derive(Debug, PartialEq, Clone)]
252267
pub struct FootprintPolygon {
253268
pub points: CoordinatePointList,
254269
pub fill: SimpleFillMode,
255270
}
256271

272+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
273+
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
257274
#[derive(Debug, PartialEq, Clone)]
258275
pub struct FootprintBezier {
259276
pub points: [Vec2D; 4],

kicad_format/src/common/footprint/text.rs

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use crate::{
99
};
1010

1111
/// A footprint text element.
12+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
13+
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
1214
#[derive(Debug, PartialEq, Clone)]
1315
pub struct FootprintText {
1416
pub kind: FootprintTextKind,
@@ -81,6 +83,8 @@ impl ToSexpr for FootprintText {
8183
///
8284
/// Reference and value always live on silkscreen (on the footprint side);
8385
/// other texts are planned to go on whatever layer the user wants.
86+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
87+
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
8488
#[derive(Debug, PartialEq, Clone, Copy)]
8589
pub enum FootprintTextKind {
8690
Reference,
@@ -97,6 +101,8 @@ simple_to_from_string! {
97101

98102
/// An extension of the normal [`Position`](crate::common::Position) struct that includes an `unlocked`
99103
/// field
104+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
105+
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
100106
#[derive(Debug, PartialEq, Clone)]
101107
pub struct FootprintTextPosition {
102108
pub x: f32,
@@ -140,6 +146,8 @@ impl ToSexpr for FootprintTextPosition {
140146
// FIXME: Really should be an enum because there are 2 valid types of text boxes
141147
// (axis aligned and partially rotated)
142148
/// A footprint text box element.
149+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
150+
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
143151
#[derive(Debug, PartialEq, Clone)]
144152
pub struct FootprintTextBox {
145153
pub locked: bool,

0 commit comments

Comments
 (0)