pub struct Variables { /* private fields */ }Expand description
Ordered set of channel variables with FreeSWITCH escaping.
A comma is escaped with \,, a backslash and a single quote with as many
backslashes as the DialStringTarget’s passes consume, a space at either
edge of a value as a \s escaped for the same passes, and a value with other
spaces is wrapped in single quotes. This form round-trips through FromStr;
what the switch itself decodes depends on which command carries the block
and which parser revision reads it, documented in docs/dial-string-format.md.
A key meets the same passes and is escaped the same way, with \= for the = split and an
empty '' ahead of one opening ^^.
A value naming a variable (${…}) is left to the switch, which expands it or
drops it at install unless origination_nested_vars is true.
§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 key or 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 key or value already
present contains it. A pair inserted afterwards is not checked: one carrying
sep splits into a pair nobody wrote, silently, until
insert becomes fallible (docs/next-major.md).
Refused: space, controls, non-ASCII, \, ' and lowercase n r t s, which break the
switch’s split or its escapes; either of the block’s brackets, = and ^; $ and {,
which dialplan expansion reads as a reference across a pair boundary; | in a [] block.
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,
target: impl Into<DialStringTarget>,
) -> VariablesDisplay<'_>
pub fn display_for( &self, target: impl Into<DialStringTarget>, ) -> VariablesDisplay<'_>
Render for a named carrier or DialStringTarget, rather than the
DialStringCarrier::EslApi default that Display uses.
Source§impl Variables
impl Variables
Sourcepub fn parse_for(
s: &str,
target: impl Into<DialStringTarget>,
) -> Result<Self, OriginateError>
pub fn parse_for( s: &str, target: impl Into<DialStringTarget>, ) -> Result<Self, OriginateError>
Parse a block written for a named carrier or DialStringTarget, as the switch installs
it there: the pairs are read through a port of every pass that target applies, so a block
display_for wrote at the same target reads back as built.
FromStr uses the DialStringCarrier::EslApi default of Display.
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.