Skip to content

Commit 4a5f5a8

Browse files
committed
Add a feature to enable/disable serde integration
1 parent 22ff1a4 commit 4a5f5a8

5 files changed

Lines changed: 11 additions & 29 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stoik/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ default-run = "stoik"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10-
serde = { version = "1.0", features = ["derive"] }
11-
serde_json = "1.0"
10+
serde = { version = "1.0", features = ["derive"], optional = true }
11+
12+
[features]
13+
serde = ["dep:serde"]

stoik/src/err.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::{error::Error, fmt::Display};
33
use crate::formula::{Molecule, SyntaxNode, TokenLoc};
44

55
#[derive(Debug)]
6+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
67
/// The error type for this crate
78
pub enum StoikError {
89
/// A token is in an invalid location

stoik/src/formula/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ use std::{
2121
fmt::{Debug, Display},
2222
};
2323

24-
use serde::{Deserialize, Serialize};
2524
pub use tokenstream::*;
2625

2726
use crate::err::StoikError;
2827

2928
/// A node in a parsed chemical equation syntax tree
30-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
29+
#[derive(Debug, Clone, PartialEq, Eq)]
30+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3131
pub enum SyntaxNode {
3232
/// A subcompund, like the `(SO4)` in `Rh2(SO4)3`
3333
Subcompound(Vec<SyntaxNode>),
@@ -155,7 +155,8 @@ fn internal_tree(
155155
}
156156
}
157157

158-
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
158+
#[derive(Debug, PartialEq, Eq, Clone)]
159+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
159160
/// A repesentaion of a molecule used for stoichiometric puroposies
160161
///
161162
/// # Examples

stoik/src/formula/tokenstream.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ impl<'a> TokenStream<'a> {
122122
}
123123

124124
#[derive(Debug)]
125+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
125126
/// One "lexical" token in a formula. It carries along its location in a formula using [`TokenLoc`]
126127
/// This is intended to be generated with [`TokenStream`]
127128
pub enum Token {
@@ -197,6 +198,7 @@ impl Display for Token {
197198
}
198199

199200
#[derive(Debug, Default, PartialEq, Eq)]
201+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
200202
/// The location of one token in a formula. Used for debugging and error reporting
201203
///
202204
/// # Examples

0 commit comments

Comments
 (0)