Iced: Can't get Command::perform to work

Created on 7 Jul 2020  路  2Comments  路  Source: hecrj/iced

Okay, I am pretty sure this is an error from my side, but I just can't seem to figure out what the issue is. I've tried comparing to multiple examples, and some other projects I found using Iced. Problem is it seem never to call my Foo::load() method, thus never calling in my match inside update. Anyone know what I am doing wrong here?

```rust
pub fn run() {
let mut settings = Settings::default();
Ajour::run(settings);
}

[derive(Debug, Clone)]

pub enum Message {
Refresh(String),
}

struct Foo {
}

impl Foo {
async fn load() -> String {
Ok(String::from("Hello"))
}
}

struct Ajour {
addon: String,
}

impl Default for Ajour {
fn default() -> Self {
Self {
addons: Default::default(),
}
}
}

impl Application for Ajour {
type Executor = executor::Null;
type Message = Message;
type Flags = ();

fn new(_flags: ()) -> (Self, Command<Message>) {
    (
        Ajour::default(),
        Command::perform(Foo::load(), Message::Refresh),
    )
}

fn update(&mut self, message: Message) -> Command<Message> {
    match message {
        Message::Refresh(_) => {
            println!("We fetched addons");
            Command::none()
        }
    }
}

fn view(&mut self) -> Element<Self::Message> {
    ....
}

}

question

Most helpful comment

Haha, jesus. I feel super stupid now.
Thank you for responding so fast @Songtronix.

All 2 comments

type Executor = executor::Null;

An executor that drops all the futures, instead of spawning them.

Your Foo::load() future just gets dropped. Try to use iced::executor::Default and it will work.

Haha, jesus. I feel super stupid now.
Thank you for responding so fast @Songtronix.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jiminycrick picture jiminycrick  路  3Comments

michael-hart picture michael-hart  路  4Comments

johannesvollmer picture johannesvollmer  路  4Comments

Newbytee picture Newbytee  路  4Comments

sumibi-yakitori picture sumibi-yakitori  路  3Comments