pub struct KeyValue { /* private fields */ }Expand description
A tree of string keys to values or child nodes.
Implementations§
Source§impl KeyValue
impl KeyValue
Sourcepub fn with_name_and_value(
name: impl Into<String>,
value: impl Into<String>,
) -> KeyValue
pub fn with_name_and_value( name: impl Into<String>, value: impl Into<String>, ) -> KeyValue
Creates a node with a name and a value.
Sourcepub fn children_mut(&mut self) -> &mut Vec<KeyValue>
pub fn children_mut(&mut self) -> &mut Vec<KeyValue>
The children of this node, for modification.
Sourcepub fn get(&self, key: &str) -> &KeyValue
pub fn get(&self, key: &str) -> &KeyValue
The child with the given key (ordinal, case-insensitive), or
KeyValue::invalid if there’s none.
Sourcepub fn set(&mut self, key: &str, value: KeyValue)
pub fn set(&mut self, key: &str, value: KeyValue)
Sets the child with the given key: removes any existing child with that
key, renames value to key and appends it.
Sourcepub fn as_unsigned_byte(&self, default_value: u8) -> u8
pub fn as_unsigned_byte(&self, default_value: u8) -> u8
The value as a u8, or default_value if it isn’t one.
Sourcepub fn as_unsigned_short(&self, default_value: u16) -> u16
pub fn as_unsigned_short(&self, default_value: u16) -> u16
The value as a u16, or default_value if it isn’t one.
Sourcepub fn as_integer(&self, default_value: i32) -> i32
pub fn as_integer(&self, default_value: i32) -> i32
The value as an i32, or default_value if it isn’t one.
Sourcepub fn as_unsigned_integer(&self, default_value: u32) -> u32
pub fn as_unsigned_integer(&self, default_value: u32) -> u32
The value as a u32, or default_value if it isn’t one.
Sourcepub fn as_long(&self, default_value: i64) -> i64
pub fn as_long(&self, default_value: i64) -> i64
The value as an i64, or default_value if it isn’t one.
Sourcepub fn as_unsigned_long(&self, default_value: u64) -> u64
pub fn as_unsigned_long(&self, default_value: u64) -> u64
The value as a u64, or default_value if it isn’t one.
Sourcepub fn as_float(&self, default_value: f32) -> f32
pub fn as_float(&self, default_value: f32) -> f32
The value as an f32, or default_value if it isn’t one.
Sourcepub fn as_boolean(&self, default_value: bool) -> bool
pub fn as_boolean(&self, default_value: bool) -> bool
The value as a boolean, or default_value if it isn’t one.
Sourcepub fn as_enum<T: FromKeyValue>(&self, default_value: T) -> T
pub fn as_enum<T: FromKeyValue>(&self, default_value: T) -> T
The value as an enum, or default_value if it isn’t one.
Source§impl KeyValue
impl KeyValue
Sourcepub async fn load_as_text(path: impl AsRef<Path>) -> Option<KeyValue>
pub async fn load_as_text(path: impl AsRef<Path>) -> Option<KeyValue>
Loads a text KeyValue from a file. None on any error.
Sourcepub async fn try_load_as_binary(path: impl AsRef<Path>) -> Option<KeyValue>
pub async fn try_load_as_binary(path: impl AsRef<Path>) -> Option<KeyValue>
Loads a binary KeyValue from a file. None on any error.
Sourcepub fn load_from_string(input: &str) -> Option<KeyValue>
pub fn load_from_string(input: &str) -> Option<KeyValue>
Parses a text KeyValue from a string. None on any error.
Sourcepub fn read_as_text(&mut self, input: &mut dyn Read) -> Result<(), SteamError>
pub fn read_as_text(&mut self, input: &mut dyn Read) -> Result<(), SteamError>
Reads this node from a text KeyValue stream.
A byte order mark is detected and stripped, so UTF-8 (EF BB BF),
UTF-16 LE (FF FE) and UTF-16 BE (FE FF) documents all work. Without
one, the bytes are read as UTF-8.
Sourcepub async fn read_file_as_text(
&mut self,
filename: impl AsRef<Path>,
) -> Result<(), SteamError>
pub async fn read_file_as_text( &mut self, filename: impl AsRef<Path>, ) -> Result<(), SteamError>
Reads this node from a text KeyValue file. The encoding is detected
like in KeyValue::read_as_text.
Sourcepub async fn save_to_file(
&self,
path: impl AsRef<Path>,
as_binary: bool,
) -> Result<(), SteamError>
pub async fn save_to_file( &self, path: impl AsRef<Path>, as_binary: bool, ) -> Result<(), SteamError>
Saves this node to a file.
Sourcepub fn save_to_stream(
&self,
stream: &mut dyn Write,
as_binary: bool,
) -> Result<(), SteamError>
pub fn save_to_stream( &self, stream: &mut dyn Write, as_binary: bool, ) -> Result<(), SteamError>
Saves this node to a stream.
Sourcepub fn try_read_as_binary(&mut self, input: &mut dyn Read) -> bool
pub fn try_read_as_binary(&mut self, input: &mut dyn Read) -> bool
Reads this node from a binary KeyValue stream. Returns false on
failure.
Trait Implementations§
impl Eq for KeyValue
impl StructuralPartialEq for KeyValue
Auto Trait Implementations§
impl Freeze for KeyValue
impl RefUnwindSafe for KeyValue
impl Send for KeyValue
impl Sync for KeyValue
impl Unpin for KeyValue
impl UnsafeUnpin for KeyValue
impl UnwindSafe for KeyValue
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,
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.