iced

Trait Program

Source
pub trait Program: Sized {
    type State;
    type Message: Send + Debug + 'static;
    type Theme: Default + Base;
    type Renderer: Renderer;
    type Executor: Executor;

    // Required methods
    fn update(
        &self,
        state: &mut Self::State,
        message: Self::Message,
    ) -> Task<Self::Message>;
    fn view<'a>(
        &self,
        state: &'a Self::State,
        window: Id,
    ) -> Element<'a, Self::Message, Self::Theme, Self::Renderer>;

    // Provided methods
    fn title(&self, _state: &Self::State, _window: Id) -> String { ... }
    fn subscription(&self, _state: &Self::State) -> Subscription<Self::Message> { ... }
    fn theme(&self, _state: &Self::State, _window: Id) -> Self::Theme { ... }
    fn style(&self, _state: &Self::State, theme: &Self::Theme) -> Style { ... }
    fn scale_factor(&self, _state: &Self::State, _window: Id) -> f64 { ... }
    fn run(
        self,
        settings: Settings,
        window_settings: Option<Settings>,
    ) -> Result
       where Self: 'static,
             Self::State: Default { ... }
    fn run_with<I>(
        self,
        settings: Settings,
        window_settings: Option<Settings>,
        initialize: I,
    ) -> Result
       where Self: 'static,
             I: FnOnce() -> (Self::State, Task<Self::Message>) + 'static { ... }
}
Expand description

The internal definition of a Program.

You should not need to implement this trait directly. Instead, use the methods available in the Program struct.

Required Associated Types§

Source

type State

The state of the program.

Source

type Message: Send + Debug + 'static

The message of the program.

Source

type Theme: Default + Base

The theme of the program.

Source

type Renderer: Renderer

The renderer of the program.

Source

type Executor: Executor

The executor of the program.

Required Methods§

Source

fn update( &self, state: &mut Self::State, message: Self::Message, ) -> Task<Self::Message>

Source

fn view<'a>( &self, state: &'a Self::State, window: Id, ) -> Element<'a, Self::Message, Self::Theme, Self::Renderer>

Provided Methods§

Source

fn title(&self, _state: &Self::State, _window: Id) -> String

Source

fn subscription(&self, _state: &Self::State) -> Subscription<Self::Message>

Source

fn theme(&self, _state: &Self::State, _window: Id) -> Self::Theme

Source

fn style(&self, _state: &Self::State, theme: &Self::Theme) -> Style

Source

fn scale_factor(&self, _state: &Self::State, _window: Id) -> f64

Source

fn run(self, settings: Settings, window_settings: Option<Settings>) -> Result
where Self: 'static, Self::State: Default,

Runs the Program.

The state of the Program must implement Default. If your state does not implement Default, use run_with instead.

Source

fn run_with<I>( self, settings: Settings, window_settings: Option<Settings>, initialize: I, ) -> Result
where Self: 'static, I: FnOnce() -> (Self::State, Task<Self::Message>) + 'static,

Runs the Program with the given Settings and a closure that creates the initial state.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§