is_tree/traits/
has_parent.rs

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