Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blob to the State::waitingForDownload variant #1

Open
rambip opened this issue Nov 23, 2021 · 0 comments
Open

Add blob to the State::waitingForDownload variant #1

rambip opened this issue Nov 23, 2021 · 0 comments

Comments

@rambip
Copy link
Owner

rambip commented Nov 23, 2021

Using an enum for the Model of your app is probably more idiomatic, but working with it with the borrow checker is harder.

Here is what you could do for State::WaitingForDownload(blob)

fn give_me_blob(&mut State) -> Option<blob> {
    // FIXME: reset state only if in State ::WaitingForDownload
    let old_state = std::mem::replace(
        self.state,
        State::Downloading
        );
     match old_state {
          WaitingForDownload(blob) => Some(blob),
          _ => None
     }
}

Here is an exemple:

https://rust-unofficial.github.io/patterns/idioms/mem-replace.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant