Skip to content

Commit 988ea07

Browse files
committed
(feat): Add serde feature flag
1 parent 5e7cdef commit 988ea07

File tree

6 files changed

+16
-0
lines changed

6 files changed

+16
-0
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ repository = "https://github.com/kevinmehall/rust-vcd"
99
categories = ["parser-implementations", "encoding"]
1010
readme = "README.md"
1111
edition = "2018"
12+
13+
[dependencies]
14+
serde = { version = "^1.0", optional = true, features = ["derive"] }

src/idcode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ impl Error for InvalidIdCode { }
2727

2828
/// An ID used within the file to refer to a particular variable.
2929
#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)]
30+
#[cfg_attr(feature="serde", derive(serde::Serialize, serde::Deserialize))]
3031
pub struct IdCode(u64);
3132

3233
const ID_CHAR_MIN: u8 = b'!';

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ pub(crate) use unit_error_struct;
146146

147147
/// An element in a VCD file.
148148
#[derive(Debug, PartialEq, Clone)]
149+
#[cfg_attr(feature="serde", derive(serde::Serialize, serde::Deserialize))]
149150
#[non_exhaustive]
150151
pub enum Command {
151152
/// A `$comment` command
@@ -198,6 +199,7 @@ pub enum Command {
198199

199200
/// A simulation command type, used in `Command::Begin` and `Command::End`.
200201
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
202+
#[cfg_attr(feature="serde", derive(serde::Serialize, serde::Deserialize))]
201203
#[non_exhaustive]
202204
#[allow(missing_docs)]
203205
pub enum SimulationCommand {
@@ -228,6 +230,7 @@ impl Display for SimulationCommand {
228230
/// A `Header` can be parsed from VCD with [`Parser::parse_header`], or create an
229231
/// empty `Header` with [`Header::default`].
230232
#[derive(Debug, Default)]
233+
#[cfg_attr(feature="serde", derive(serde::Serialize, serde::Deserialize))]
231234
#[non_exhaustive]
232235
pub struct Header {
233236
/// `$date` text

src/scope.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::IdCode;
55

66
/// A type of scope, as used in the `$scope` command.
77
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
8+
#[cfg_attr(feature="serde", derive(serde::Serialize, serde::Deserialize))]
89
#[non_exhaustive]
910
#[allow(missing_docs)]
1011
pub enum ScopeType {
@@ -51,6 +52,7 @@ impl Display for ScopeType {
5152

5253
/// A type of variable, as used in the `$var` command.
5354
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
55+
#[cfg_attr(feature="serde", derive(serde::Serialize, serde::Deserialize))]
5456
#[non_exhaustive]
5557
#[allow(missing_docs)]
5658
pub enum VarType {
@@ -136,6 +138,7 @@ impl Display for VarType {
136138

137139
/// Information on a VCD scope as represented by a `$scope` command and its children.
138140
#[derive(Debug, Clone, PartialEq)]
141+
#[cfg_attr(feature="serde", derive(serde::Serialize, serde::Deserialize))]
139142
#[non_exhaustive]
140143
pub struct Scope {
141144
/// Type of scope.
@@ -186,6 +189,7 @@ impl Default for Scope {
186189
/// assert_eq!("[7:0]".parse(), Ok(ReferenceIndex::Range(7, 0)));
187190
/// ```
188191
#[derive(Debug, Copy, Clone, PartialEq)]
192+
#[cfg_attr(feature="serde", derive(serde::Serialize, serde::Deserialize))]
189193
pub enum ReferenceIndex {
190194
/// Single bit (e.g `[0]`)
191195
BitSelect(i32),
@@ -245,6 +249,7 @@ fn test_parse_reference_index() {
245249

246250
/// Information on a VCD variable as represented by a `$var` command.
247251
#[derive(Debug, Clone, PartialEq)]
252+
#[cfg_attr(feature="serde", derive(serde::Serialize, serde::Deserialize))]
248253
#[non_exhaustive]
249254
pub struct Var {
250255
/// Type of variable.
@@ -281,6 +286,7 @@ impl Var {
281286

282287
/// An item in a scope
283288
#[derive(Debug, Clone, PartialEq)]
289+
#[cfg_attr(feature="serde", derive(serde::Serialize, serde::Deserialize))]
284290
#[non_exhaustive]
285291
pub enum ScopeItem {
286292
/// `$scope` - Child scope

src/timescale.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::str::FromStr;
33

44
/// A unit of time for the `$timescale` command.
55
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
6+
#[cfg_attr(feature="serde", derive(serde::Serialize, serde::Deserialize))]
67
pub enum TimescaleUnit {
78
/// Second
89
S,

src/value.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::str::FromStr;
44

55
/// A four-valued logic scalar value.
66
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
7+
#[cfg_attr(feature="serde", derive(serde::Serialize, serde::Deserialize), serde(tag = "type"))]
78
pub enum Value {
89
/// Logic low
910
///
@@ -79,6 +80,7 @@ impl Display for Value {
7980
/// This currently wraps a `Vec<Value>` but could be implemented with
8081
/// a bitmap in the future.
8182
#[derive(Clone, PartialEq, Eq)]
83+
#[cfg_attr(feature="serde", derive(serde::Serialize, serde::Deserialize))]
8284
pub struct Vector(Vec<Value>);
8385

8486
impl Vector {

0 commit comments

Comments
 (0)