Skip to content

Commit 8f5957a

Browse files
committed
rust: adt: Add ADTNode::root() convenience function
Simplifies referencing the root ADT node in rust code. Signed-off-by: Janne Grunau <[email protected]>
1 parent 9c4e969 commit 8f5957a

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

rust/src/adt.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,17 +277,22 @@ impl ADTNode {
277277
}
278278
}
279279

280+
/// Get a reference to the root node
281+
pub fn root() -> Result<&'static ADTNode, AdtError> {
282+
let ptr: *const ADTNode = unsafe { adt as *const ADTNode };
283+
ADTNode::from_ptr(ptr)
284+
}
285+
280286
/// Get a reference to a node at a specified path, tracing the path to the
281287
/// desired node
282288
pub fn from_path_trace(
283289
path: &str,
284290
mut breadcrumbs: Option<&mut [Option<&'static ADTNode>]>,
285291
) -> Result<&'static ADTNode, AdtError> {
286-
let ptr: *const ADTNode = unsafe { adt as *const ADTNode };
287292
let mut p = path;
288293
let mut bc_idx: usize = 0;
289294

290-
let head = ADTNode::from_ptr(ptr)?;
295+
let head = ADTNode::root()?;
291296
let mut n = head;
292297

293298
while !p.is_empty() {

0 commit comments

Comments
 (0)