Trait wildland_catlib::contracts::IContainer
source · [−]pub trait IContainer {
fn uuid(&self) -> Uuid;
fn forest(&self) -> CatlibResult<Forest>;
fn paths(&self) -> ContainerPaths;
fn add_path(&mut self, path: ContainerPath) -> CatlibResult<Container>;
fn del_path(&mut self, path: ContainerPath) -> CatlibResult<Container>;
fn storages(&self) -> CatlibResult<Vec<Storage>>;
fn create_storage(
&self,
template_uuid: Option<Uuid>,
data: Vec<u8>
) -> CatlibResult<Storage>;
}
Required Methods
sourcefn forest(&self) -> CatlibResult<Forest>
fn forest(&self) -> CatlibResult<Forest>
Return Forest
that contains the Container
.
Errors
- Returns
CatlibError::NoRecordsFound
if noForest
was found. - Returns
CatlibError::MalformedDatabaseEntry
if more than oneForest
was found.
sourcefn paths(&self) -> ContainerPaths
fn paths(&self) -> ContainerPaths
Return Container
’s paths
sourcefn add_path(&mut self, path: ContainerPath) -> CatlibResult<Container>
fn add_path(&mut self, path: ContainerPath) -> CatlibResult<Container>
Add a path to the Container.
Returns self to allow chain method exection.
Errors
Returns RustbreakError
cast on CatlibResult
upon failure to save to the database.
Example
let catlib = CatLib::default();
let forest = catlib.create_forest(
Identity([1; 32]),
HashSet::from([Identity([2; 32])]),
vec![],
).unwrap();
let mut container = forest.create_container().unwrap();
container.add_path("/bar/baz2".to_string()).unwrap()
.add_path("/baz/qux1".to_string()).unwrap()
.add_path("/baz/qux2".to_string()).unwrap();
sourcefn del_path(&mut self, path: ContainerPath) -> CatlibResult<Container>
fn del_path(&mut self, path: ContainerPath) -> CatlibResult<Container>
Delete a path from the Container.
Returns self to allow chain method exection.
Errors
Returns RustbreakError
cast on CatlibResult
upon failure to save to the database.
Example
let catlib = CatLib::default();
let forest = catlib.create_forest(
Identity([1; 32]),
HashSet::from([Identity([2; 32])]),
vec![],
).unwrap();
let mut container = forest.create_container().unwrap();
container.add_path("/bar/baz2".to_string()).unwrap()
.del_path("/baz/qux1".to_string()).unwrap()
.del_path("/baz/qux2".to_string()).unwrap();
sourcefn storages(&self) -> CatlibResult<Vec<Storage>>
fn storages(&self) -> CatlibResult<Vec<Storage>>
Return list of Forest Storage
s.
Errors
Returns CatlibError::NoRecordsFound
if Forest has no Storage
.
sourcefn create_storage(
&self,
template_uuid: Option<Uuid>,
data: Vec<u8>
) -> CatlibResult<Storage>
fn create_storage(
&self,
template_uuid: Option<Uuid>,
data: Vec<u8>
) -> CatlibResult<Storage>
Create a Storage
, bound to the Container
.
template_uuid
is an arbitrary, optional, String
that is later used to find
Container
s and Storage
s using CatLib::find_storages_with_template
and
CatLib::find_containers_with_template
.
data
represents arbitrary data that is defined and used by the DF/S module.
Errors
Returns RustbreakError
cast on CatlibResult
upon failure to save to the database.
Example
let catlib = CatLib::default();
let forest = catlib.create_forest(
Identity([1; 32]),
HashSet::from([Identity([2; 32])]),
vec![],
).unwrap();
let mut container = forest.create_container().unwrap();
container.add_path("/foo/bar".to_string());
container.create_storage(Some(Uuid::from_u128(1)), vec![]).unwrap();