Expand description
Value
binding and helper traits.
The type of a Value
is dynamic in that it generally
isn’t known at compile time but once created a Value
can’t change its
type.
SendValue
is a version of Value
that can only store types that implement Send
and as such implements Send
itself. It
dereferences to Value
so it can be used everywhere Value
references are accepted.
Supported types are bool
, i8
, u8
, i32
, u32
, i64
, u64
, f32
,
f64
, String
and objects (T: IsA<Object>
).
§Examples
use glib::prelude::*; // or `use gtk::prelude::*;`
use glib::Value;
// Value implement From<&i32>, From<&str> and From<Option<&str>>.
// Another option is the `ToValue` trait.
let mut num = 10.to_value();
let mut hello = Value::from("Hello!");
let none: Option<&str> = None;
let str_none = none.to_value();
// `is` tests the type of the value.
assert!(num.is::<i32>());
assert!(hello.is::<String>());
// `get` tries to get an optional value of the specified type
// and returns an `Err` if the type doesn't match.
assert_eq!(num.get(), Ok(10));
assert!(num.get::<String>().is_err());
assert_eq!(hello.get(), Ok(String::from("Hello!")));
assert_eq!(hello.get::<String>(), Ok(String::from("Hello!")));
assert_eq!(str_none.get::<Option<String>>(), Ok(None));
Structs§
- Boxed
Value - A
Value
containing anotherValue
. - Char
Type Checker - Generic
Value Type Checker - Generic
Value
type checker for types. - Generic
Value Type OrNone Checker - Generic
Value
type checker for optional types. - NopChecker
- Send
Value - A version of
Value
for storingSend
types, that implements Send itself. - Value
- A generic value capable of carrying various types.
- Value
Type Mismatch Error - An error returned from the
get
function on aValue
for non-optional types anOption
. - Value
Type OrNone Checker - Wrapped
Value
type checker for optional types.
Enums§
- Invalid
Char Error - An error returned from the
get
function on aValue
for char (which are internally u32) types. - Value
Type Mismatch OrNone Error - An error returned from the
get
function on aValue
for optional types.
Traits§
- From
Value - Trait to retrieve the contained value from a
Value
. - From
Value Optional - Trait for types that implement
FromValue
and are Optional. - ToSend
Value - Converts to
SendValue
. - ToValue
- Trait to convert a value to a
Value
. - ToValue
Optional - Trait to convert an
Option
to aValue
for optional types. - Value
Type - A type that can be stored in
Value
s. - Value
Type Checker - Trait for
Value
type checkers. - Value
Type Optional - A type that can be stored in
Value
s and is optional.