Struct browser_window::application::ApplicationHandleThreaded[][src]

pub struct ApplicationHandleThreaded { /* fields omitted */ }
Expand description

Note: Only available with feature threadsafe enabled.

A thread-safe application handle. This handle also allows you to dispatch code to be executed on the GUI thread from any other thread.

Implementations

Executes the given closure func on the GUI thread, and gives back the result when done. This only works when the runtime is still running. If the closure panicked, or the runtime is not running, this will return an error.

The function signature is practically the same as:

pub async fn delegate<'a,F,R>( &self, func: F ) -> Result<R, DelegateError> where
	F: FnOnce( ApplicationHandle ) -> R + Send + 'a,
	R: Send { /* ... */ }

Keep in mind that in multi-threaded environments, it is generally a good idea to put the output on the heap. The output value will be copied.

Example

let my_value: String = app.delegate(|handle| {
	"String".to_owned()
}).unwrap();

Executes the given future on the GUI thread, and gives back its output when done. This only works when the runtime is still running. If the future panicked during a poll, or the runtime is not running, this will return an error. See also delegate.

The function signature is practically the same as:

pub async fn delegate_future<'a,F,R>( &self, func: F ) -> Result<R, DelegateError> where
	F: Future<Output=R> + 'static,,
	R: Send { /* ... */ }

Example

let my_value: String = app.delegate_future(async {
	"String".to_owned()
}).unwrap();

Executes the given async closure func on the GUI thread, and gives back the result when done. This only works when the runtime is still running. If the closure panicked, or the runtime is not running, this will return an error.

Except, async closures are not yet supported in stable Rust. What we actually mean are closures of the form:

|handle| async move { /* ... */ }

The function signature is practically the same as:

pub async fn delegate_async<'a,C,F,R>( &self, func: C ) -> Result<R, DelegateError> where
	C: FnOnce( ApplicationHandle ) -> F + Send + 'a,
	F: Future<Output=R>,
	R: Send + 'static
{ /* ... */ }

Example

let my_value: String = app.delegate_async(|handle| async move {
	"String".to_owned()
}).unwrap();

Queues the given closure func to be executed on the GUI thread somewhere in the future. The closure will only execute when and if the runtime is still running. Returns whether or not the closure will be able to execute.

Queues the given async closure func to be executed on the GUI thread somewhere in the future. The closure will only execute when and if the runtime is still running. However, there is no guarantee that the whole closure will execute. The runtime might exit when the given closure is at a point of waiting. Returns whether or not the closure will be able to execute its first part.

Signals the runtime to exit. This will cause Runtime::run to stop and return the provided exit code.

Executes the given future on the GUI thread somewhere in the near future.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.