is_tree/traits/
has_root.rs

1//! A trait for types that have a root.
2
3use crate::KnowsVisitor;
4
5/// A trait for types that have a root.
6pub trait HasRoot: KnowsVisitor {
7    /// Gets the root of the object.
8    fn root(&self) -> Self::Visitor;
9}
10
11/// A trait for types that have a root mutably.
12/// By design, accessing a Visitor parent is unsafe.
13pub unsafe trait HasRootMut: KnowsVisitor {
14    /// Gets the root of the object.
15    unsafe fn root_mut(&mut self) -> Self::VisitorMut;
16}
17
18impl<T> HasRoot for Box<T>
19where T: HasRoot
20{
21    fn root(&self) -> Self::Visitor {
22        self.as_ref().root()
23    }
24}
25
26unsafe impl<T> HasRootMut for Box<T>
27where T: HasRootMut
28{
29    unsafe fn root_mut(&mut self) -> Self::VisitorMut {
30        self.as_mut().root_mut()
31    }
32}