Struct fltk::app::prefs::Preferences

source ·
pub struct Preferences { /* private fields */ }
Expand description

Provides methods to store user settings between application starts

Implementations§

source§

impl Preferences

source

pub fn set_file_access(flags: FileAccess)

Set filesystem access

source

pub fn file_access() -> FileAccess

Get filesystem access flags

source

pub fn new(root: Root, vendor: &str, application: &str) -> Option<Self>

Create a new Preferences object

Examples found in repository?
examples/prefs.rs (line 4)
3
4
5
6
7
8
9
10
11
12
13
14
fn main() {
    let mut prefs = Preferences::new(Root::USER_L, "myfltk.org", "tempapp").unwrap();
    let mut opts = Preferences::new_group(&mut prefs, "Options").unwrap();
    opts.set_int("winsize", 400).unwrap();
    let size = opts.get_int("winsize").unwrap_or(300);
    opts.set_str("wintitle", "Hello").unwrap();
    let title = opts.get_str("wintitle").unwrap_or("My Window".to_string());
    println!("{}", size);
    println!("{}", title);
    println!("{:?}", opts.name());
    println!("{:?}", prefs.filename());
}
source

pub fn new_group(parent: &mut Preferences, group: &str) -> Option<Self>

Create a preferences object entry inside the group

Examples found in repository?
examples/prefs.rs (line 5)
3
4
5
6
7
8
9
10
11
12
13
14
fn main() {
    let mut prefs = Preferences::new(Root::USER_L, "myfltk.org", "tempapp").unwrap();
    let mut opts = Preferences::new_group(&mut prefs, "Options").unwrap();
    opts.set_int("winsize", 400).unwrap();
    let size = opts.get_int("winsize").unwrap_or(300);
    opts.set_str("wintitle", "Hello").unwrap();
    let title = opts.get_str("wintitle").unwrap_or("My Window".to_string());
    println!("{}", size);
    println!("{}", title);
    println!("{:?}", opts.name());
    println!("{:?}", prefs.filename());
}
source

pub fn path(&self) -> String

Get the prefs path

source

pub fn filename(&self) -> Result<(PathBuf, Root), FltkError>

Get the filename

Examples found in repository?
examples/prefs.rs (line 13)
3
4
5
6
7
8
9
10
11
12
13
14
fn main() {
    let mut prefs = Preferences::new(Root::USER_L, "myfltk.org", "tempapp").unwrap();
    let mut opts = Preferences::new_group(&mut prefs, "Options").unwrap();
    opts.set_int("winsize", 400).unwrap();
    let size = opts.get_int("winsize").unwrap_or(300);
    opts.set_str("wintitle", "Hello").unwrap();
    let title = opts.get_str("wintitle").unwrap_or("My Window".to_string());
    println!("{}", size);
    println!("{}", title);
    println!("{:?}", opts.name());
    println!("{:?}", prefs.filename());
}
source

pub fn get_userdata_path(&self) -> Result<PathBuf, FltkError>

Get the userdata path

source

pub fn set_int(&mut self, entry: &str, val: i32) -> Result<(), FltkError>

Set the value of an entry

Examples found in repository?
examples/prefs.rs (line 6)
3
4
5
6
7
8
9
10
11
12
13
14
fn main() {
    let mut prefs = Preferences::new(Root::USER_L, "myfltk.org", "tempapp").unwrap();
    let mut opts = Preferences::new_group(&mut prefs, "Options").unwrap();
    opts.set_int("winsize", 400).unwrap();
    let size = opts.get_int("winsize").unwrap_or(300);
    opts.set_str("wintitle", "Hello").unwrap();
    let title = opts.get_str("wintitle").unwrap_or("My Window".to_string());
    println!("{}", size);
    println!("{}", title);
    println!("{:?}", opts.name());
    println!("{:?}", prefs.filename());
}
source

pub fn get_int(&mut self, entry: &str) -> Result<i32, FltkError>

Get the value of an entry

Examples found in repository?
examples/prefs.rs (line 7)
3
4
5
6
7
8
9
10
11
12
13
14
fn main() {
    let mut prefs = Preferences::new(Root::USER_L, "myfltk.org", "tempapp").unwrap();
    let mut opts = Preferences::new_group(&mut prefs, "Options").unwrap();
    opts.set_int("winsize", 400).unwrap();
    let size = opts.get_int("winsize").unwrap_or(300);
    opts.set_str("wintitle", "Hello").unwrap();
    let title = opts.get_str("wintitle").unwrap_or("My Window".to_string());
    println!("{}", size);
    println!("{}", title);
    println!("{:?}", opts.name());
    println!("{:?}", prefs.filename());
}
source

pub fn set_float(&mut self, entry: &str, val: f32) -> Result<(), FltkError>

Set the value of an entry

source

pub fn set_float_with_precision( &mut self, entry: &str, val: f32, precision: u16 ) -> Result<(), FltkError>

Set the value of an entry

source

pub fn get_float(&mut self, entry: &str) -> Result<f32, FltkError>

Get the value of an entry

source

pub fn set_double(&mut self, entry: &str, val: f64) -> Result<(), FltkError>

Set the value of an entry

source

pub fn set_double_with_precision( &mut self, entry: &str, val: f64, precision: u16 ) -> Result<(), FltkError>

Set the value of an entry

source

pub fn get_double(&mut self, entry: &str) -> Result<f64, FltkError>

Get the value of an entry

source

pub fn set_str(&mut self, entry: &str, val: &str) -> Result<(), FltkError>

Set the value of an entry

Examples found in repository?
examples/prefs.rs (line 8)
3
4
5
6
7
8
9
10
11
12
13
14
fn main() {
    let mut prefs = Preferences::new(Root::USER_L, "myfltk.org", "tempapp").unwrap();
    let mut opts = Preferences::new_group(&mut prefs, "Options").unwrap();
    opts.set_int("winsize", 400).unwrap();
    let size = opts.get_int("winsize").unwrap_or(300);
    opts.set_str("wintitle", "Hello").unwrap();
    let title = opts.get_str("wintitle").unwrap_or("My Window".to_string());
    println!("{}", size);
    println!("{}", title);
    println!("{:?}", opts.name());
    println!("{:?}", prefs.filename());
}
source

pub fn get_str(&mut self, entry: &str) -> Result<String, FltkError>

Get the value of an entry

Examples found in repository?
examples/prefs.rs (line 9)
3
4
5
6
7
8
9
10
11
12
13
14
fn main() {
    let mut prefs = Preferences::new(Root::USER_L, "myfltk.org", "tempapp").unwrap();
    let mut opts = Preferences::new_group(&mut prefs, "Options").unwrap();
    opts.set_int("winsize", 400).unwrap();
    let size = opts.get_int("winsize").unwrap_or(300);
    opts.set_str("wintitle", "Hello").unwrap();
    let title = opts.get_str("wintitle").unwrap_or("My Window".to_string());
    println!("{}", size);
    println!("{}", title);
    println!("{:?}", opts.name());
    println!("{:?}", prefs.filename());
}
source

pub fn name(&mut self) -> Option<String>

Return the pref’s name

Examples found in repository?
examples/prefs.rs (line 12)
3
4
5
6
7
8
9
10
11
12
13
14
fn main() {
    let mut prefs = Preferences::new(Root::USER_L, "myfltk.org", "tempapp").unwrap();
    let mut opts = Preferences::new_group(&mut prefs, "Options").unwrap();
    opts.set_int("winsize", 400).unwrap();
    let size = opts.get_int("winsize").unwrap_or(300);
    opts.set_str("wintitle", "Hello").unwrap();
    let title = opts.get_str("wintitle").unwrap_or("My Window".to_string());
    println!("{}", size);
    println!("{}", title);
    println!("{:?}", opts.name());
    println!("{:?}", prefs.filename());
}
source

pub fn groups(&mut self) -> i32

Return the number of groups

source

pub fn group_exists(&mut self, key: &str) -> bool

Check whether a group exists

source

pub fn delete_group(&mut self, group: &str) -> Result<(), FltkError>

Delete a group

source

pub fn delete_all_groups(&mut self) -> Result<(), FltkError>

Delete all groups

source

pub fn entries(&mut self) -> i32

Return the number of entries

source

pub fn entry_exists(&mut self, key: &str) -> bool

Check whether an entry exists

source

pub fn delete_entry(&mut self, entry: &str) -> Result<(), FltkError>

Delete an entry

source

pub fn delete_all_entries(&mut self) -> Result<(), FltkError>

Delete all entries

source

pub fn clear(&mut self) -> Result<(), FltkError>

Clear prefs

Trait Implementations§

source§

impl Clone for Preferences

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Preferences

source§

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

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

impl Drop for Preferences

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> ToOwned for Twhere T: Clone,

§

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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.