Skip to content

Commit 1c423d8

Browse files
authored
Merge pull request #1 from TTWNO/serde_feature_flag
2 parents f7f669c + d58c732 commit 1c423d8

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

html-node-core/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ version.workspace = true
1717

1818
[dependencies]
1919
axum = { version = "0.6", optional = true, default-features = false }
20+
serde = { version = "1.0", optional = true, features = ["derive"] }
2021

2122
html-escape = "0.2"
2223
paste = "1.0.14"
2324

2425
[features]
2526
axum = ["dep:axum"]
2627
typed = []
28+
serde = ["dep:serde"]

html-node-core/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use self::typed::TypedElement;
2121

2222
/// An HTML node.
2323
#[derive(Debug, Clone, PartialEq, Eq)]
24+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2425
pub enum Node {
2526
/// A comment.
2627
///
@@ -116,6 +117,7 @@ impl Display for Node {
116117
/// <!-- I'm a comment! -->
117118
/// ```
118119
#[derive(Debug, Clone, PartialEq, Eq)]
120+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
119121
pub struct Comment {
120122
/// The text of the comment.
121123
///
@@ -137,6 +139,7 @@ impl Display for Comment {
137139
/// <!DOCTYPE html>
138140
/// ```
139141
#[derive(Debug, Clone, PartialEq, Eq)]
142+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
140143
pub struct Doctype {
141144
/// The value of the doctype.
142145
///
@@ -160,6 +163,7 @@ impl Display for Doctype {
160163
/// </>
161164
/// ```
162165
#[derive(Debug, Clone, PartialEq, Eq)]
166+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
163167
pub struct Fragment {
164168
/// The children of the fragment.
165169
///
@@ -185,6 +189,7 @@ impl Display for Fragment {
185189
/// </div>
186190
/// ```
187191
#[derive(Debug, Clone, PartialEq, Eq)]
192+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
188193
pub struct Element {
189194
/// The name of the element.
190195
///
@@ -250,6 +255,7 @@ impl Display for Element {
250255
/// I'm a text node!
251256
/// </div>
252257
#[derive(Debug, Clone, PartialEq, Eq)]
258+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
253259
pub struct Text {
254260
/// The text of the node.
255261
///
@@ -274,6 +280,7 @@ impl Display for Text {
274280
/// [`UnsafeText`] is not escaped when rendered, and as such, can allow
275281
/// for XSS attacks. Use with caution!
276282
#[derive(Debug, Clone, PartialEq, Eq)]
283+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
277284
pub struct UnsafeText {
278285
/// The text of the node.
279286
pub text: String,

html-node/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
3737
[features]
3838
axum = ["html-node-core/axum"]
3939
typed = ["html-node-core/typed", "html-node-macro/typed"]
40+
serde = ["html-node-core/serde"]

0 commit comments

Comments
 (0)