Skip to main content

PresetStore

Struct PresetStore 

Source
pub struct PresetStore { /* private fields */ }
Expand description

One plugin’s preset library across all three scopes, with the management operations layered on top of the discovery walk.

enumerate applies the identity rule: two presets with the same uuid in different scopes are the same logical preset, and the more user-proximate copy wins (User over Pack over Factory) so a user “override” of a factory preset shows once, not twice. Mutations only ever touch the user scope.

Implementations§

Source§

impl PresetStore

Source

pub fn new( vendor: &str, plugin_name: &str, plugin_id_hash: u64, user_dir: Option<&str>, ) -> PresetStore

A store for the given plugin identity. The user root resolves from the per-OS environment, honouring the optional [plugin.presets] user_dir override (see user_preset_root for where the path lands per OS); the factory root (inside the installed bundle) is format-specific, so callers that have one add it via Self::with_factory_root.

Source

pub fn with_factory_root(self, root: impl Into<PathBuf>) -> PresetStore

Source

pub fn with_user_root(self, root: impl Into<PathBuf>) -> PresetStore

Override the user root (tests, tools operating on a staged library).

Source

pub fn user_root(&self) -> Option<&Path>

Source

pub fn enumerate(&self) -> Vec<PresetRef>

Every preset across factory, user, and pack scopes, deduped by uuid (User wins over Pack wins over Factory), ordered factory-first then by category / name within each scope.

User / pack files that arrived without a uuid (hand-assembled packs, pre-tool files) get one minted and written back on first read, so their identity is stable from then on; write-back failures degrade to an empty uuid rather than hiding the preset.

Source

pub fn find(&self, sel: &str) -> Option<PresetRef>

Resolve a preset by truce-preset:// URI, bare uuid, or display name. A URI for a different vendor / plugin returns None. Name matching is a fallback after uuid (names are unique per category by library validation; on a cross-category name clash the first in enumeration order wins).

Source

pub fn load(&self, uri_or_uuid: &str) -> Result<DeserializedState, PresetError>

Load a preset’s state, validating it against this plugin’s identity hash.

§Errors

PresetError::NotFound for an unknown URI; PresetError::InvalidState when the file’s envelope doesn’t parse or belongs to a different plugin.

Source

pub fn save( &self, meta: PresetMeta, params: &[(u32, f64)], extra: &[u8], ) -> Result<PresetRef, PresetError>

Save a preset into the user scope.

A user preset with the same (category, name) is overwritten in place, keeping its uuid - the natural “Save” gesture. Otherwise a new file is created with a minted uuid (or meta.uuid when the caller pre-assigned one). meta.name is the display name; the file lands at <user root>/<category>/<name>.trucepreset.

§Errors

PresetError::NoUserDirectory when the per-OS root can’t be resolved, PresetError::InvalidName for a name that sanitizes to nothing, PresetError::Io on write failure.

Source

pub fn rename( &self, uri_or_uuid: &str, new_name: &str, ) -> Result<(), PresetError>

Rename a user preset’s display name. The uuid (and therefore the URI and any host-side reference) is unchanged; the file keeps its on-disk name.

§Errors

PresetError::NotFound, PresetError::ReadOnlyScope for factory / pack presets, PresetError::InvalidState for a file that no longer parses, PresetError::Io.

Source

pub fn recategorise( &self, uri_or_uuid: &str, new_category: &str, ) -> Result<(), PresetError>

Move a user preset to a different category. Rewrites the explicit category metadata and moves the file into the matching directory so the on-disk layout stays readable. The uuid is unchanged.

§Errors

Same surface as Self::rename, plus PresetError::NoUserDirectory.

Source

pub fn delete(&self, uri_or_uuid: &str) -> Result<(), PresetError>

Delete a user preset.

§Errors

PresetError::NotFound, PresetError::ReadOnlyScope for factory / pack presets, PresetError::Io.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.