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
impl ParamValues
Sourcepub fn new() -> Self
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}pub fn set(&mut self, name: &str, value: ParamValue)
Sourcepub fn with_float(self, name: &str, x: f64) -> Self
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}Sourcepub fn with_bool(self, name: &str, b: bool) -> Self
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}Sourcepub fn with_choice(self, name: &str, c: &str) -> Self
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}pub fn get(&self, name: &str) -> Option<&ParamValue>
Sourcepub fn iter(&self) -> impl Iterator<Item = (&str, &ParamValue)>
pub fn iter(&self) -> impl Iterator<Item = (&str, &ParamValue)>
Entries in name order.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn resolve(&self, specs: &[ParamSpec]) -> Result<ParamValues, PluginError>
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.
Sourcepub fn float(&self, name: &str) -> f64
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.
Sourcepub fn bool(&self, name: &str) -> bool
pub fn bool(&self, name: &str) -> bool
A resolved bool. Panics under the same condition as ParamValues::float.
Sourcepub fn choice(&self, name: &str) -> &str
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
impl Clone for ParamValues
Source§impl Debug for ParamValues
impl Debug for ParamValues
Source§impl Default for ParamValues
impl Default for ParamValues
Source§impl PartialEq for ParamValues
impl PartialEq for ParamValues
impl StructuralPartialEq for ParamValues
Auto Trait Implementations§
impl Forget for ParamValues
impl Freeze for ParamValueswhere
*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
impl Sync for ParamValues
impl Unpin for ParamValues
impl UnsafeUnpin for ParamValueswhere
*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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more