Trait cvars::SetGet

source ·
pub trait SetGet {
    fn get_string(&self, cvar_name: &str) -> Result<String, String>;
    fn set_str(&mut self, cvar_name: &str, str_value: &str) -> Result<(), String>;
}
Expand description

A trait for writing generic code that can access cvars but doesn’t know the concrete Cvars struct.

This is implemented automatically by both #[derive(SetGet)] and cvars! {}.

The methods provided here call those implemented directly on the concrete Cvars struct, there is no difference between them.

Implementation note: This trait can’t include the get and set methods because it would no longer be object-safe.

Required Methods§

source

fn get_string(&self, cvar_name: &str) -> Result<String, String>

Finds the cvar whose name matches cvar_name and returns it’s value as a String.

Returns Err if the cvar doesn’t exist.

source

fn set_str(&mut self, cvar_name: &str, str_value: &str) -> Result<(), String>

Finds the cvar whose name matches cvar_name, tries to parse str_value to its type and sets it to the parsed value.

Returns Err if the cvar doesn’t exist or if str_value fails to parse to its type.

Implementors§