pub struct CategoryRegistry { /* private fields */ }Expand description
In-memory category store, persisted to a single TOML file.
All public methods that mutate state (create, edit, remove)
are expected to be paired with a save call by the caller — the
session actor wraps these in a single critical section to avoid
tearing. Concurrent reads through get and list are safe when
the registry is wrapped in a parking_lot::RwLock.
Implementations§
Source§impl CategoryRegistry
impl CategoryRegistry
Sourcepub fn new(path: PathBuf) -> CategoryRegistry
pub fn new(path: PathBuf) -> CategoryRegistry
Create a new in-memory registry bound to path. The file is not
touched until the first save.
Sourcepub fn load(path: PathBuf) -> CategoryRegistry
pub fn load(path: PathBuf) -> CategoryRegistry
Load a registry from its TOML file at path.
On failure this method is lenient: a missing file yields an
empty registry (lazy materialisation); a malformed file is
renamed to <name>.bak (or <name>.bak.N on collision) and an
empty registry is returned so the session can still start.
Sourcepub fn get(&self, name: &str) -> Option<&CategoryMetadata>
pub fn get(&self, name: &str) -> Option<&CategoryMetadata>
Look up a category by name. Returns None for the empty-string
name (qBt convention: empty means “uncategorised”).
Sourcepub fn contains(&self, name: &str) -> bool
pub fn contains(&self, name: &str) -> bool
True when the registry contains a category with name.
Sourcepub fn list(&self) -> Vec<CategoryMetadata>
pub fn list(&self) -> Vec<CategoryMetadata>
All categories as an unordered list. Callers that need stable
ordering should sort by name.
Sourcepub fn create(
&mut self,
name: String,
save_path: PathBuf,
) -> Result<(), CategoryError>
pub fn create( &mut self, name: String, save_path: PathBuf, ) -> Result<(), CategoryError>
Create a new category.
§Errors
Returns CategoryError::InvalidName if name fails validation,
or CategoryError::AlreadyExists if a category with that name
is already registered. Does NOT persist to disk — call
save after successful mutation.
Sourcepub fn edit(
&mut self,
name: &str,
save_path: PathBuf,
) -> Result<(), CategoryError>
pub fn edit( &mut self, name: &str, save_path: PathBuf, ) -> Result<(), CategoryError>
Update the save_path for an existing category.
§Errors
Returns CategoryError::NotFound if no category with name
is registered, or CategoryError::InvalidName if name itself
is malformed.
Sourcepub fn remove(&mut self, names: &[String]) -> Vec<String>
pub fn remove(&mut self, names: &[String]) -> Vec<String>
Remove zero or more categories. Unknown names are silently
ignored (qBt behaviour). Returns the list of names that were
actually removed so callers can clear the category label on
any torrents that pointed at them.
Sourcepub fn save(&self) -> Result<(), CategoryError>
pub fn save(&self) -> Result<(), CategoryError>
Atomically persist this registry to disk.
Writes to a sibling temp file in the same directory, then
persist() renames into place. Creates parent directories as
needed.
§Errors
Returns CategoryError::Persistence on I/O failure and
CategoryError::Serialise if TOML encoding fails (should be
impossible given the schema is all-String + PathBuf).
Trait Implementations§
Source§impl Clone for CategoryRegistry
impl Clone for CategoryRegistry
Source§fn clone(&self) -> CategoryRegistry
fn clone(&self) -> CategoryRegistry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more