Skip to main content

KeyValue

Struct KeyValue 

Source
pub struct KeyValue { /* private fields */ }
Expand description

A tree of string keys to values or child nodes.

Implementations§

Source§

impl KeyValue

Source

pub fn new() -> KeyValue

Creates an empty node.

Source

pub fn with_name(name: impl Into<String>) -> KeyValue

Creates a node with a name.

Source

pub fn with_name_and_value( name: impl Into<String>, value: impl Into<String>, ) -> KeyValue

Creates a node with a name and a value.

Source

pub fn invalid() -> &'static KeyValue

The node returned when a looked-up child doesn’t exist.

Source

pub fn name(&self) -> Option<&str>

The name of this node.

Source

pub fn set_name(&mut self, name: Option<String>)

Sets the name of this node.

Source

pub fn value(&self) -> Option<&str>

The value of this node.

Source

pub fn set_value(&mut self, value: Option<String>)

Sets the value of this node.

Source

pub fn children(&self) -> &[KeyValue]

The children of this node.

Source

pub fn children_mut(&mut self) -> &mut Vec<KeyValue>

The children of this node, for modification.

Source

pub fn get(&self, key: &str) -> &KeyValue

The child with the given key (ordinal, case-insensitive), or KeyValue::invalid if there’s none.

Source

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.

Source

pub fn as_string(&self) -> Option<&str>

The value as a string.

Source

pub fn as_unsigned_byte(&self, default_value: u8) -> u8

The value as a u8, or default_value if it isn’t one.

Source

pub fn as_unsigned_short(&self, default_value: u16) -> u16

The value as a u16, or default_value if it isn’t one.

Source

pub fn as_integer(&self, default_value: i32) -> i32

The value as an i32, or default_value if it isn’t one.

Source

pub fn as_unsigned_integer(&self, default_value: u32) -> u32

The value as a u32, or default_value if it isn’t one.

Source

pub fn as_long(&self, default_value: i64) -> i64

The value as an i64, or default_value if it isn’t one.

Source

pub fn as_unsigned_long(&self, default_value: u64) -> u64

The value as a u64, or default_value if it isn’t one.

Source

pub fn as_float(&self, default_value: f32) -> f32

The value as an f32, or default_value if it isn’t one.

Source

pub fn as_boolean(&self, default_value: bool) -> bool

The value as a boolean, or default_value if it isn’t one.

Source

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

Source

pub async fn load_as_text(path: impl AsRef<Path>) -> Option<KeyValue>

Loads a text KeyValue from a file. None on any error.

Source

pub async fn try_load_as_binary(path: impl AsRef<Path>) -> Option<KeyValue>

Loads a binary KeyValue from a file. None on any error.

Source

pub fn load_from_string(input: &str) -> Option<KeyValue>

Parses a text KeyValue from a string. None on any error.

Source

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.

Source

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.

Source

pub async fn save_to_file( &self, path: impl AsRef<Path>, as_binary: bool, ) -> Result<(), SteamError>

Saves this node to a file.

Source

pub fn save_to_stream( &self, stream: &mut dyn Write, as_binary: bool, ) -> Result<(), SteamError>

Saves this node to a stream.

Source

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§

Source§

impl Clone for KeyValue

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for KeyValue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for KeyValue

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for KeyValue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for KeyValue

Source§

impl PartialEq for KeyValue

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for KeyValue

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more