pub trait LinkedResource<'a, T: Display> {
// Required methods
fn child(&self) -> Option<&Self>;
fn parent(&self) -> Option<&Self>;
fn is_child(&self) -> bool;
fn is_root(&self) -> bool;
fn is_tail(&self) -> bool;
fn with_child(
&mut self,
child: &mut ApiResource<'a, T>,
) -> Result<Box<Self>>;
fn with_parent(
&mut self,
parent: &mut ApiResource<'a, T>,
) -> Result<Box<Self>>;
}
Expand description
Allows resources to set their child and parent nodes.
Required Methods§
Sourcefn is_child(&self) -> bool
fn is_child(&self) -> bool
If this is a child of another resource.
Initialy created object should produce a non-child node.
use uri_resources::{ApiResource, LinkedResource};
let resource = ApiResource::<String>::new("resource");
assert_eq!(resource.is_child(), false)
Try to create an instance of two nodes where one is related to the other as the parent.
use uri_resources::{ApiResource, LinkedResource};
let mut child = ApiResource::<String>::new("child_resource");
let parent = ApiResource::<String>::new("parent_resource")
.with_child(&mut child);
assert_eq!(child.is_child(), true)
Sourcefn is_root(&self) -> bool
fn is_root(&self) -> bool
If this is the first resource of the path.
Initialy created object should produce a root node.
use uri_resources::{ApiResource, LinkedResource};
let resource = ApiResource::<String>::new("resource");
assert_eq!(resource.is_root(), true)
Subsequent objects should not be a root node.
use uri_resources::{ApiResource, LinkedResource};
let mut child = ApiResource::<String>::new("child_resource");
let parent = ApiResource::<String>::new("parent_resource")
.with_child(&mut child);
assert_ne!(child.is_root(), true)
Sourcefn is_tail(&self) -> bool
fn is_tail(&self) -> bool
If this is the last resource of the path.
Root node can be a tail node if it is the only resource node.
use uri_resources::{ApiResource, LinkedResource};
let resource = ApiResource::<String>::new("resource");
assert!(resource.is_tail())
If there are otherwise child nodes, a root node cannot be the ‘tail’.
use uri_resources::{ApiResource, LinkedResource};
let mut child0 = ApiResource::<String>::new("child_resource0");
let mut child1 = ApiResource::<String>::new("child_resource1");
child0 = *child0.with_child(&mut child1).expect("resource node");
let parent = ApiResource::<String>::new("parent_resource")
.with_child(&mut child0);
assert!(!parent.expect("parent node").is_tail())
The middle child cannot be the tail.
use uri_resources::{ApiResource, LinkedResource};
let mut child0 = ApiResource::<String>::new("child_resource0");
let mut child1 = ApiResource::<String>::new("child_resource1");
child0 = *child0.with_child(&mut child1).expect("resource node");
let parent = ApiResource::<String>::new("parent_resource")
.with_child(&mut child0);
assert!(child0.is_child() && !child0.is_tail());
The last child should be the tail.
use uri_resources::{ApiResource, LinkedResource};
let mut child0 = ApiResource::<String>::new("child_resource0");
let mut child1 = ApiResource::<String>::new("child_resource1");
child0 = *child0.with_child(&mut child1).expect("resource node");
let parent = ApiResource::<String>::new("parent_resource")
.with_child(&mut child0);
assert!(child1.is_child() && child1.is_tail())
Sourcefn with_child(&mut self, child: &mut ApiResource<'a, T>) -> Result<Box<Self>>
fn with_child(&mut self, child: &mut ApiResource<'a, T>) -> Result<Box<Self>>
Adds a child node to this resource. Fails if the child is already set.
Sourcefn with_parent(&mut self, parent: &mut ApiResource<'a, T>) -> Result<Box<Self>>
fn with_parent(&mut self, parent: &mut ApiResource<'a, T>) -> Result<Box<Self>>
Adds the parent node to this resource. Fails if the parent is already set.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.