pub struct Variables { /* private fields */ }Expand description
Ordered set of channel variables with FreeSWITCH escaping.
Backslashes are doubled, commas are escaped with \,, single quotes with
\', and values with spaces are wrapped in single quotes. This form
round-trips through FromStr; what the switch itself decodes depends on
which command carries the block, and is documented in
docs/dial-string-format.md.
§Serde format
Default scope with the comma separator
serializes as a flat JSON map: {"key": "value", ...}. Anything else
serializes as {"scope": "enterprise", "vars": {"key": "value"}}, carrying
a "separator" field only when with_separator
chose one. Deserialization accepts both formats; a flat map implies
Default scope and the comma. A separator that cannot delimit the block,
or that a value already contains, is refused at load.
Implementations§
Source§impl Variables
impl Variables
Sourcepub fn new(vars_type: VariablesType) -> Self
pub fn new(vars_type: VariablesType) -> Self
Create an empty variable set with the given scope.
Sourcepub fn with_vars(
vars_type: VariablesType,
vars: impl IntoIterator<Item = (impl Into<String>, impl Into<String>)>,
) -> Self
pub fn with_vars( vars_type: VariablesType, vars: impl IntoIterator<Item = (impl Into<String>, impl Into<String>)>, ) -> Self
Create from an existing set of key-value pairs.
Sourcepub fn with_separator(self, sep: char) -> Result<Self, OriginateError>
pub fn with_separator(self, sep: char) -> Result<Self, OriginateError>
Separate the pairs with sep instead of a comma, emitting the block in
FreeSWITCH’s ^^<sep> form.
A value expanded from ${...} in a dialplan is substituted before the
block is parsed, so no escaping can be inserted into it; choosing a
separator none of the values contain is the only way such a value can
carry a comma. The separator is given rather than derived, so a block
renders the same way whatever its values happen to be that call.
Fails if sep cannot delimit this block, or if a value already present
contains it. A value inserted afterwards is not checked: one carrying
sep splits into a pair nobody wrote, silently, until
insert becomes fallible (docs/next-major.md).
Sourcepub fn separator(&self) -> Option<char>
pub fn separator(&self) -> Option<char>
The ^^ separator this block renders with, if one was chosen.
Sourcepub fn insert(&mut self, key: impl Into<String>, value: impl Into<String>)
pub fn insert(&mut self, key: impl Into<String>, value: impl Into<String>)
Insert or overwrite a variable.
Sourcepub fn remove(&mut self, key: &str) -> Option<String>
pub fn remove(&mut self, key: &str) -> Option<String>
Remove a variable by name, returning its value if it existed.
Sourcepub fn scope(&self) -> VariablesType
pub fn scope(&self) -> VariablesType
Variable scope (Enterprise, Default, or Channel).
Sourcepub fn set_scope(&mut self, scope: VariablesType)
pub fn set_scope(&mut self, scope: VariablesType)
Change the variable scope.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&str, &str)>
pub fn iter(&self) -> impl Iterator<Item = (&str, &str)>
Iterate over key-value pairs in insertion order.
Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = (&str, &mut String)>
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&str, &mut String)>
Mutable iterator over key-value pairs in insertion order.
Sourcepub fn values_mut(&mut self) -> impl Iterator<Item = &mut String>
pub fn values_mut(&mut self) -> impl Iterator<Item = &mut String>
Mutable iterator over values in insertion order.
Source§impl Variables
impl Variables
Sourcepub fn display_for(&self, carrier: DialStringCarrier) -> VariablesDisplay<'_>
pub fn display_for(&self, carrier: DialStringCarrier) -> VariablesDisplay<'_>
Render for a named carrier, rather than the DialStringCarrier::EslApi
default that Display uses.
Source§impl Variables
impl Variables
Sourcepub fn parse_for(
s: &str,
carrier: DialStringCarrier,
) -> Result<Self, OriginateError>
pub fn parse_for( s: &str, carrier: DialStringCarrier, ) -> Result<Self, OriginateError>
Parse a block written for a named carrier, mirroring
display_for. FromStr uses the same
DialStringCarrier::EslApi default as Display, so
the two round-trip.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Variables
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Variables
serde only.Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
impl Eq for Variables
impl StructuralPartialEq for Variables
Auto Trait Implementations§
impl Freeze for Variables
impl RefUnwindSafe for Variables
impl Send for Variables
impl Sync for Variables
impl Unpin for Variables
impl UnsafeUnpin for Variables
impl UnwindSafe for Variables
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.