Struct glib::value::AnyValue[][src]

pub struct AnyValue { /* fields omitted */ }

A container type that allows storing any 'static type that implements Any and Clone to be stored in a Value.

See the module documentation for more details.

Examples

use glib::prelude::*; // or `use gtk::prelude::*;`
use glib::{AnyValue, Value};

// Store a Rust string inside a Value
let v = AnyValue::new(String::from("123")).to_value();

// Retrieve the Rust String from the the Value again
let any_v = v.get::<&AnyValue>()
    .expect("Value did not actually contain an AnyValue");
assert_eq!(any_v.downcast_ref::<String>(), Some(&String::from("123")));

Methods

impl AnyValue
[src]

Create a new AnyValue from val

Attempt the value to its concrete type.

Methods from Deref<Target = Any>

Returns true if the boxed type is the same as T.

Examples

use std::any::Any;

fn is_string(s: &Any) {
    if s.is::<String>() {
        println!("It's a string!");
    } else {
        println!("Not a string...");
    }
}

fn main() {
    is_string(&0);
    is_string(&"cookie monster".to_string());
}

Returns some reference to the boxed value if it is of type T, or None if it isn't.

Examples

use std::any::Any;

fn print_if_string(s: &Any) {
    if let Some(string) = s.downcast_ref::<String>() {
        println!("It's a string({}): '{}'", string.len(), string);
    } else {
        println!("Not a string...");
    }
}

fn main() {
    print_if_string(&0);
    print_if_string(&"cookie monster".to_string());
}

Forwards to the method defined on the type Any.

Examples

use std::any::Any;

fn is_string(s: &(Any + Send)) {
    if s.is::<String>() {
        println!("It's a string!");
    } else {
        println!("Not a string...");
    }
}

fn main() {
    is_string(&0);
    is_string(&"cookie monster".to_string());
}

Forwards to the method defined on the type Any.

Examples

use std::any::Any;

fn print_if_string(s: &(Any + Send)) {
    if let Some(string) = s.downcast_ref::<String>() {
        println!("It's a string({}): '{}'", string.len(), string);
    } else {
        println!("Not a string...");
    }
}

fn main() {
    print_if_string(&0);
    print_if_string(&"cookie monster".to_string());
}

Forwards to the method defined on the type Any.

Examples

use std::any::Any;

fn is_string(s: &(Any + Send + Sync)) {
    if s.is::<String>() {
        println!("It's a string!");
    } else {
        println!("Not a string...");
    }
}

fn main() {
    is_string(&0);
    is_string(&"cookie monster".to_string());
}

Forwards to the method defined on the type Any.

Examples

use std::any::Any;

fn print_if_string(s: &(Any + Send + Sync)) {
    if let Some(string) = s.downcast_ref::<String>() {
        println!("It's a string({}): '{}'", string.len(), string);
    } else {
        println!("Not a string...");
    }
}

fn main() {
    print_if_string(&0);
    print_if_string(&"cookie monster".to_string());
}

Trait Implementations

impl Clone for AnyValue
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for AnyValue
[src]

Formats the value using the given formatter. Read more

impl Deref for AnyValue
[src]

The resulting type after dereferencing.

Dereferences the value.

impl<'a> FromValueOptional<'a> for &'a AnyValue
[src]

impl SetValue for AnyValue
[src]

impl StaticType for AnyValue
[src]

Returns the type identifier of Self.

Auto Trait Implementations

impl !Send for AnyValue

impl !Sync for AnyValue