Skip to main content

ParamValues

Struct ParamValues 

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

Values for one use of a plugin, by parameter name. Missing names mean the default.

Implementations§

Source§

impl ParamValues

Source

pub fn new() -> Self

Examples found in repository?
examples/apply_chain.rs (line 37)
32fn parse_step(registry: &Registry, text: &str) -> Result<PluginInstance, String> {
33    let (bypass, text) = text.strip_prefix('!').map_or((false, text), |t| (true, t));
34    let (name, args) = text.split_once(':').unwrap_or((text, ""));
35    let id = if name.contains('.') { name.to_string() } else { format!("weirdnet.{name}") };
36    let plugin = registry.get(&id).ok_or_else(|| format!("no plugin {id:?}; have {}", registry.ids().collect::<Vec<_>>().join(", ")))?;
37    let mut values = ParamValues::new();
38    for pair in args.split(',').filter(|p| !p.is_empty()) {
39        let (key, raw) = pair.split_once('=').ok_or_else(|| format!("{pair:?} is not name=value"))?;
40        let spec = plugin.params().iter().find(|s| s.name == key).ok_or_else(|| format!("{id} has no parameter {key:?}"))?;
41        values = match &spec.kind {
42            ParamKind::Float => values.with_float(key, raw.parse().map_err(|_| format!("{key}: {raw:?} is not a number"))?),
43            ParamKind::Bool => values.with_bool(key, raw.parse().map_err(|_| format!("{key}: {raw:?} is not true or false"))?),
44            ParamKind::Choice(_) => values.with_choice(key, raw),
45        };
46    }
47    Ok(PluginInstance { plugin: id, values, bypass })
48}
Source

pub fn set(&mut self, name: &str, value: ParamValue)

Source

pub fn with_float(self, name: &str, x: f64) -> Self

Examples found in repository?
examples/apply_chain.rs (line 42)
32fn parse_step(registry: &Registry, text: &str) -> Result<PluginInstance, String> {
33    let (bypass, text) = text.strip_prefix('!').map_or((false, text), |t| (true, t));
34    let (name, args) = text.split_once(':').unwrap_or((text, ""));
35    let id = if name.contains('.') { name.to_string() } else { format!("weirdnet.{name}") };
36    let plugin = registry.get(&id).ok_or_else(|| format!("no plugin {id:?}; have {}", registry.ids().collect::<Vec<_>>().join(", ")))?;
37    let mut values = ParamValues::new();
38    for pair in args.split(',').filter(|p| !p.is_empty()) {
39        let (key, raw) = pair.split_once('=').ok_or_else(|| format!("{pair:?} is not name=value"))?;
40        let spec = plugin.params().iter().find(|s| s.name == key).ok_or_else(|| format!("{id} has no parameter {key:?}"))?;
41        values = match &spec.kind {
42            ParamKind::Float => values.with_float(key, raw.parse().map_err(|_| format!("{key}: {raw:?} is not a number"))?),
43            ParamKind::Bool => values.with_bool(key, raw.parse().map_err(|_| format!("{key}: {raw:?} is not true or false"))?),
44            ParamKind::Choice(_) => values.with_choice(key, raw),
45        };
46    }
47    Ok(PluginInstance { plugin: id, values, bypass })
48}
Source

pub fn with_bool(self, name: &str, b: bool) -> Self

Examples found in repository?
examples/apply_chain.rs (line 43)
32fn parse_step(registry: &Registry, text: &str) -> Result<PluginInstance, String> {
33    let (bypass, text) = text.strip_prefix('!').map_or((false, text), |t| (true, t));
34    let (name, args) = text.split_once(':').unwrap_or((text, ""));
35    let id = if name.contains('.') { name.to_string() } else { format!("weirdnet.{name}") };
36    let plugin = registry.get(&id).ok_or_else(|| format!("no plugin {id:?}; have {}", registry.ids().collect::<Vec<_>>().join(", ")))?;
37    let mut values = ParamValues::new();
38    for pair in args.split(',').filter(|p| !p.is_empty()) {
39        let (key, raw) = pair.split_once('=').ok_or_else(|| format!("{pair:?} is not name=value"))?;
40        let spec = plugin.params().iter().find(|s| s.name == key).ok_or_else(|| format!("{id} has no parameter {key:?}"))?;
41        values = match &spec.kind {
42            ParamKind::Float => values.with_float(key, raw.parse().map_err(|_| format!("{key}: {raw:?} is not a number"))?),
43            ParamKind::Bool => values.with_bool(key, raw.parse().map_err(|_| format!("{key}: {raw:?} is not true or false"))?),
44            ParamKind::Choice(_) => values.with_choice(key, raw),
45        };
46    }
47    Ok(PluginInstance { plugin: id, values, bypass })
48}
Source

pub fn with_choice(self, name: &str, c: &str) -> Self

Examples found in repository?
examples/apply_chain.rs (line 44)
32fn parse_step(registry: &Registry, text: &str) -> Result<PluginInstance, String> {
33    let (bypass, text) = text.strip_prefix('!').map_or((false, text), |t| (true, t));
34    let (name, args) = text.split_once(':').unwrap_or((text, ""));
35    let id = if name.contains('.') { name.to_string() } else { format!("weirdnet.{name}") };
36    let plugin = registry.get(&id).ok_or_else(|| format!("no plugin {id:?}; have {}", registry.ids().collect::<Vec<_>>().join(", ")))?;
37    let mut values = ParamValues::new();
38    for pair in args.split(',').filter(|p| !p.is_empty()) {
39        let (key, raw) = pair.split_once('=').ok_or_else(|| format!("{pair:?} is not name=value"))?;
40        let spec = plugin.params().iter().find(|s| s.name == key).ok_or_else(|| format!("{id} has no parameter {key:?}"))?;
41        values = match &spec.kind {
42            ParamKind::Float => values.with_float(key, raw.parse().map_err(|_| format!("{key}: {raw:?} is not a number"))?),
43            ParamKind::Bool => values.with_bool(key, raw.parse().map_err(|_| format!("{key}: {raw:?} is not true or false"))?),
44            ParamKind::Choice(_) => values.with_choice(key, raw),
45        };
46    }
47    Ok(PluginInstance { plugin: id, values, bypass })
48}
Source

pub fn get(&self, name: &str) -> Option<&ParamValue>

Source

pub fn iter(&self) -> impl Iterator<Item = (&str, &ParamValue)>

Entries in name order.

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn resolve(&self, specs: &[ParamSpec]) -> Result<ParamValues, PluginError>

Checks every value against specs (unknown names, wrong types and out-of-range values are errors) and fills in the defaults. The result has exactly one value per spec, so two uses that mean the same thing resolve to equal values.

Source

pub fn float(&self, name: &str) -> f64

A resolved float. Panics if the name is not a resolved float, which only a plugin with a mismatched spec can cause.

Source

pub fn bool(&self, name: &str) -> bool

A resolved bool. Panics under the same condition as ParamValues::float.

Source

pub fn choice(&self, name: &str) -> &str

A resolved choice. Panics under the same condition as ParamValues::float.

Trait Implementations§

Source§

impl Clone for ParamValues

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ParamValues

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ParamValues

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for ParamValues

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ParamValues

Auto Trait Implementations§

§

impl Forget for ParamValues

§

impl Freeze for ParamValues
where *const LeafNode<String, ParamValue> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<(String, ParamValue)>>: Freeze,

§

impl Move for ParamValues

§

impl RefUnwindSafe for ParamValues

§

impl Send for ParamValues
where NodeRef<Owned, String, ParamValue, LeafOrInternal>: Send, BoxRaw<(String, ParamValue)>: Send,

§

impl Sync for ParamValues
where NodeRef<Owned, String, ParamValue, LeafOrInternal>: Sync, BoxRaw<(String, ParamValue)>: Sync,

§

impl Unpin for ParamValues
where *const LeafNode<String, ParamValue> is !null: Unpin, Box<(String, ParamValue)>: Unpin,

§

impl UnsafeUnpin for ParamValues
where *const LeafNode<String, ParamValue> is !null: UnsafeUnpin, PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin, PhantomData<Box<(String, ParamValue)>>: UnsafeUnpin,

§

impl UnwindSafe for ParamValues

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.