pub trait PathComponent {
// Required methods
fn as_path_component(&self) -> Result<String>;
fn compose(&self) -> Result<String>;
}Expand description
Composes an object into a path component, conditionally failing if the implemented instance does not meet the requirements set by it’s declaration.
Ensure resources can be digested as path components.
use uri_resources::{ApiResource, PathComponent};
let path = ApiResource::<String>::new("resource").as_path_component();
assert!(!path.is_err())Required Methods§
Sourcefn as_path_component(&self) -> Result<String>
fn as_path_component(&self) -> Result<String>
Composes this as a path component.
Ensure resources can be digested and return the expected value.
use uri_resources::{ApiResource, PathComponent};
let path = ApiResource::<String>::new("resource").as_path_component();
assert_eq!(path.unwrap(), String::from("resource/"))Sourcefn compose(&self) -> Result<String>
fn compose(&self) -> Result<String>
Compose the entire heirarchy of components into one string.
Ensure the composition of a multi node collection can be composed into a single String value without error.
use uri_resources::{ApiResource, LinkedResource, PathComponent};
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);
let path = parent.expect("parent node").compose();
assert!(!path.is_err())Ensure the composition of a multi node collection can be composed into a single String value without error.
use uri_resources::{ApiResource, LinkedResource, PathComponent};
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);
let path = parent.expect("parent node").compose();
assert_eq!(path.expect("composed path"), "parent_resource/child_resource0/child_resource1/")