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 const fn is_indexed_array(&self) -> bool
pub const fn is_indexed_array(&self) -> bool
Returns whether or not the value is an indexed array, including a declared but unset one.
Sourcepub const fn is_associative_array(&self) -> bool
pub const fn is_associative_array(&self) -> bool
Returns whether or not the value is an associative array, including a declared but unset one.
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.
§Errors
Returns error::ErrorKind::Unimplemented if the literal has
misaligned keys and values.
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.
§Errors
Returns error::ErrorKind::FormattingError if writing the formatted
text fails, or any error from resolving a dynamic 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.
§Errors
Returns error::ErrorKind::ArrayIndexOutOfRange if the value is an
indexed array and index is negative and reaches before the first
element.
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.
§Errors
Returns error::ErrorKind::FormattingError if formatting an array
value fails.
Trait Implementations§
Source§impl Clone for ShellValue
impl Clone for ShellValue
Source§impl Debug for ShellValue
impl Debug for ShellValue
Source§impl<'de> Deserialize<'de> for ShellValue
Available on crate feature serde only.
impl<'de> Deserialize<'de> for ShellValue
serde only.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>,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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<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