Struct gtk_test::Observer

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

Used to wait for a widget’s signal.

It’s recommended to use it with the [observer_new] macro.

Example:

extern crate gtk;
#[macro_use]
extern crate gtk_test;

use gtk::prelude::GtkWindowExt;

gtk::init().expect("initialization failed");
let window = gtk::Window::new(gtk::WindowType::Toplevel);

let observer = observer_new!(window, connect_activate_focus, |_|);
window.emit_activate_focus();
observer.wait();

Implementations§

source§

impl Observer

source

pub fn new() -> Observer

Returns a new observer.

It’s recommended to not use it directly as is but instead to use the [observer_new] macro.

But anyway, here’s an example using it as is:

extern crate gtk;
#[macro_use]
extern crate gtk_test;

use gtk::prelude::GtkWindowExt;

gtk::init().expect("GTK init failed");

let window = gtk::Window::new(gtk::WindowType::Toplevel);

let observer = gtk_test::Observer::new();
let inner = observer.get_inner().clone();
window.connect_activate_focus(move |_| {
    *inner.borrow_mut() = true;
});

window.emit_activate_focus();
observer.wait();
source

pub fn get_inner(&self) -> &Rc<RefCell<bool>>

Returns the inner field. Just don’t use it.

source

pub fn wait(&self)

Wait for the signal to be triggered.

extern crate gtk;
#[macro_use]
extern crate gtk_test;

use gtk::prelude::GtkWindowExt;

gtk::init().expect("initialization failed");
let window = gtk::Window::new(gtk::WindowType::Toplevel);

let observer = observer_new!(window, connect_activate_focus, |_|);
window.emit_activate_focus();
observer.wait();

Trait Implementations§

source§

impl Default for Observer

source§

fn default() -> Self

Returns the “default value” for a 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, 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.