pub struct Params(/* private fields */);Expand description
The parameters of a custom control kind, by name.
These are every field a manifest carried beside kind for a kind the library does
not know, kept as data so the factory registered for the kind can read them. The
accessors answer None when a parameter is absent or of another type, so a factory
reports what it needed rather than guessing.
§Examples
use pamoja_profile::{Param, Params};
let params = Params::new()
.with("warn_below", 2.0)
.with("latching", true)
.with("zone", "north");
assert_eq!(params.number("warn_below"), Some(2.0));
assert_eq!(params.flag("latching"), Some(true));
assert_eq!(params.text("zone"), Some("north"));
assert_eq!(params.number("zone"), None);
assert_eq!(params.get("missing"), None);
assert!(matches!(params.get("zone"), Some(Param::Text(_))));Implementations§
Source§impl Params
impl Params
Sourcepub fn from_json(text: &str) -> Result<Self>
pub fn from_json(text: &str) -> Result<Self>
Loads parameters from the JSON object a manifest carries beside a custom kind.
§Arguments
text- the JSON object.
§Returns
The parameters.
§Errors
Returns Error::Codec if the text is not an object
of numbers, flags, and text.
Sourcepub fn to_json(&self) -> Result<String>
pub fn to_json(&self) -> Result<String>
Writes the parameters as the JSON object a manifest carries beside a custom kind.
§Returns
The JSON text, on one line.
§Errors
Returns Error::Codec if the parameters cannot be
serialized.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Params
impl<'de> Deserialize<'de> for Params
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Params
Auto Trait Implementations§
impl Freeze for Params
impl RefUnwindSafe for Params
impl Send for Params
impl Sync for Params
impl Unpin for Params
impl UnsafeUnpin for Params
impl UnwindSafe for Params
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