pub enum ShellValue {
Unset(ShellValueUnsetType),
String(String),
AssociativeArray(BTreeMap<String, String>),
IndexedArray(BTreeMap<u64, String>),
Dynamic {
getter: fn(&dyn ShellState) -> ShellValue,
setter: fn(&dyn ShellState),
},
}Expand description
A shell value.
Variants§
Unset(ShellValueUnsetType)
A value that has been typed but not yet set.
String(String)
A string.
AssociativeArray(BTreeMap<String, String>)
An associative array.
IndexedArray(BTreeMap<u64, String>)
An indexed array.
Dynamic
A value that is dynamically computed.
Fields
getter: fn(&dyn ShellState) -> ShellValueFunction that can query the value. TODO(serde): figure out how to serialize/deserialize dynamic values.
setter: fn(&dyn ShellState)Function that receives value update requests. TODO(serde): figure out how to serialize/deserialize dynamic values.
Implementations§
Source§impl ShellValue
impl ShellValue
Sourcepub fn indexed_array_from_strings<S>(values: S) -> Selfwhere
S: IntoIterator<Item = String>,
pub fn indexed_array_from_strings<S>(values: S) -> Selfwhere
S: IntoIterator<Item = String>,
Returns a new indexed array value constructed from the given slice of owned strings.
§Arguments
values- The slice of strings to construct the indexed array from.
Sourcepub fn indexed_array_from_strs(values: &[&str]) -> Self
pub fn indexed_array_from_strs(values: &[&str]) -> Self
Returns a new indexed array value constructed from the given slice of unowned strings.
§Arguments
values- The slice of strings to construct the indexed array from.
Sourcepub fn indexed_array_from_literals(literals: ArrayLiteral) -> Self
pub fn indexed_array_from_literals(literals: ArrayLiteral) -> Self
Returns a new indexed array value constructed from the given literals.
§Arguments
literals- The literals to construct the indexed array from.
Sourcepub fn associative_array_from_literals(
literals: ArrayLiteral,
) -> Result<Self, Error>
pub fn associative_array_from_literals( literals: ArrayLiteral, ) -> Result<Self, Error>
Returns a new associative array value constructed from the given literals.
§Arguments
literals- The literals to construct the associative array from.
Sourcepub fn format(
&self,
style: FormatStyle,
shell: &Shell<impl ShellExtensions>,
) -> Result<Cow<'_, str>, Error>
pub fn format( &self, style: FormatStyle, shell: &Shell<impl ShellExtensions>, ) -> Result<Cow<'_, str>, Error>
Formats the value using the given style.
§Arguments
style- The style to use for formatting the value.
Sourcepub fn get_at(
&self,
index: &str,
shell: &Shell<impl ShellExtensions>,
) -> Result<Option<Cow<'_, str>>, Error>
pub fn get_at( &self, index: &str, shell: &Shell<impl ShellExtensions>, ) -> Result<Option<Cow<'_, str>>, Error>
Tries to retrieve the value stored at the given index in this variable.
§Arguments
index- The index at which to retrieve the value.
Sourcepub fn element_keys(&self, shell: &Shell<impl ShellExtensions>) -> Vec<String>
pub fn element_keys(&self, shell: &Shell<impl ShellExtensions>) -> Vec<String>
Returns the keys of the elements in this variable.
Sourcepub fn element_values(&self, shell: &Shell<impl ShellExtensions>) -> Vec<String>
pub fn element_values(&self, shell: &Shell<impl ShellExtensions>) -> Vec<String>
Returns the values of the elements in this variable.
Sourcepub fn to_cow_str(&self, shell: &Shell<impl ShellExtensions>) -> Cow<'_, str>
pub fn to_cow_str(&self, shell: &Shell<impl ShellExtensions>) -> Cow<'_, str>
Converts this value to a string.
Sourcepub fn try_get_cow_str(
&self,
shell: &Shell<impl ShellExtensions>,
) -> Option<Cow<'_, str>>
pub fn try_get_cow_str( &self, shell: &Shell<impl ShellExtensions>, ) -> Option<Cow<'_, str>>
Tries to convert this value to a string; returns None if the value is unset
or otherwise doesn’t exist.
Sourcepub fn to_assignable_str(
&self,
index: Option<&str>,
shell: &Shell<impl ShellExtensions>,
) -> Result<String, Error>
pub fn to_assignable_str( &self, index: Option<&str>, shell: &Shell<impl ShellExtensions>, ) -> Result<String, Error>
Formats this value as a program string usable in an assignment.
§Arguments
index- The index at which to retrieve the value, if indexing is to be performed.
Trait Implementations§
Source§impl Clone for ShellValue
impl Clone for ShellValue
Source§fn clone(&self) -> ShellValue
fn clone(&self) -> ShellValue
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ShellValue
impl Debug for ShellValue
Source§impl From<&String> for ShellValue
impl From<&String> for ShellValue
Source§impl From<&str> for ShellValue
impl From<&str> for ShellValue
Source§impl From<OsString> for ShellValue
impl From<OsString> for ShellValue
Source§impl From<String> for ShellValue
impl From<String> for ShellValue
Auto Trait Implementations§
impl Freeze for ShellValue
impl RefUnwindSafe for ShellValue
impl Send for ShellValue
impl Sync for ShellValue
impl Unpin for ShellValue
impl UnsafeUnpin for ShellValue
impl UnwindSafe for ShellValue
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,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more