diff --git a/01.workspace/heave/src/imp/catalog_ensure_init.rs b/01.workspace/heave/src/imp/catalog_ensure_init.rs new file mode 100644 index 0000000..d6b61f2 --- /dev/null +++ b/01.workspace/heave/src/imp/catalog_ensure_init.rs @@ -0,0 +1,12 @@ +use crate::*; + +impl Catalog { + pub fn ensure_init(&mut self) -> Result<(), FailedTo> { + if self.already_init { + return Ok(()); + } + let result = self.init()?; + self.already_init = true; + Ok(()) + } +} diff --git a/01.workspace/heave/src/imp/mod.rs b/01.workspace/heave/src/imp/mod.rs index cd85b9d..49dc13b 100644 --- a/01.workspace/heave/src/imp/mod.rs +++ b/01.workspace/heave/src/imp/mod.rs @@ -1,6 +1,7 @@ pub mod bool_try_from_value; pub mod catalog_contains_key; pub mod catalog_delete; +pub mod catalog_ensure_init; pub mod catalog_for_each; pub mod catalog_for_each_mut; pub mod catalog_get; diff --git a/01.workspace/heave/src/str/catalog.rs b/01.workspace/heave/src/str/catalog.rs index a071943..7fd7348 100644 --- a/01.workspace/heave/src/str/catalog.rs +++ b/01.workspace/heave/src/str/catalog.rs @@ -10,6 +10,7 @@ use std::sync::*; #[derive(Debug, Default)] pub struct O { pub(crate) path: String, + pub(crate) already_init: bool, items: Mutex>, }