Skip to content

Commit 36c1655

Browse files
committed
Fix using RawNode recursively by resetting it to the previous value instead of always resetting it None.
1 parent 924acb7 commit 36c1655

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"
88
repository = "https://github.com/adamreichold/serde-roxmltree"
99
documentation = "https://docs.rs/serde-roxmltree"
1010
readme = "README.md"
11-
version = "0.9.0"
11+
version = "0.9.1"
1212
edition = "2021"
1313

1414
[dependencies]

src/raw_node.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,15 @@ where
9393
{
9494
let _reset_curr_node = match &this.source {
9595
Source::Node(node) if ptr::eq(name, RAW_NODE_NAME) => {
96+
let reset_curr_node = ResetCurrNode(CURR_NODE.get());
97+
9698
#[allow(unsafe_code)]
9799
// SAFETY: The guard will reset this before `deserialize_struct` returns.
98100
CURR_NODE.set(Some(unsafe {
99101
transmute::<Node<'de, 'input>, Node<'static, 'static>>(*node)
100102
}));
101103

102-
Some(ResetCurrNode)
104+
Some(reset_curr_node)
103105
}
104106
_ => None,
105107
};
@@ -113,11 +115,11 @@ thread_local! {
113115
static CURR_NODE: Cell<Option<Node<'static, 'static>>> = const { Cell::new(None) };
114116
}
115117

116-
struct ResetCurrNode;
118+
struct ResetCurrNode(Option<Node<'static, 'static>>);
117119

118120
impl Drop for ResetCurrNode {
119121
fn drop(&mut self) {
120-
CURR_NODE.set(None);
122+
CURR_NODE.set(self.0.take());
121123
}
122124
}
123125

0 commit comments

Comments
 (0)