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 doc to direct developers to enable features for iced::time::every #2188

Merged
merged 2 commits into from
Feb 5, 2024
Merged

Add doc to direct developers to enable features for iced::time::every #2188

merged 2 commits into from
Feb 5, 2024

Conversation

fogarecious
Copy link
Contributor

Online document of Iced has the function iced::time::every. However, this function cannot be called when using thread-pool backend.

This PR adds doc to explicitly direct developers to enable appropriate features. This does not change any compiled code.

@fogarecious
Copy link
Contributor Author

This comment provides a more detailed explanation of the PR.

The online document has a function named iced::time::every. As outlined in the document, there are no constraints on using this function, particularly requiring any specific features. However, when calling the function as shown below:

struct MyApp;

impl iced::Application for MyApp {
    type Executor = iced::executor::Default;
    type Message = iced::time::Instant;
    type Theme = iced::Theme;
    type Flags = ();

    fn new(_flags: Self::Flags) -> (Self, iced::Command<Self::Message>) {
        (Self, iced::Command::none())
    }

    fn title(&self) -> String {
        "".into()
    }

    fn update(&mut self, _message: Self::Message) -> iced::Command<Self::Message> {
        iced::Command::none()
    }

    fn view(&self) -> iced::Element<'_, Self::Message, iced::Renderer<Self::Theme>> {
        "".into()
    }

    fn subscription(&self) -> iced::Subscription<Self::Message> {
        iced::time::every(std::time::Duration::from_secs(1))
    }
}

and including the following dependencies in the Cargo.toml file:

[dependencies]
iced = "0.10.0"

it leads to a compiler error:

error[E0425]: cannot find function `every` in module `iced::time`

To address this issue, the simplest solution is to enable one of the following features: tokio, async-std, or smol.

This PR includes documentation for the function, explicitly instructing developers to enable the mentioned features.

While this may potentially be a cargo doc issue, it proved to be quite confusing for me, requiring a significant amount of time to identify the source of the error. I hope this PR can assist other developers facing the same problem.

(If you believe the problem is not significant, please inform me, and I will close the PR.)

@hecrj hecrj added this to the 0.12 milestone Feb 5, 2024
Copy link
Member

@hecrj hecrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I made some changes to use doc_cfg instead.

@hecrj hecrj enabled auto-merge February 5, 2024 23:41
@hecrj hecrj merged commit 6f97b62 into iced-rs:master Feb 5, 2024
13 checks passed
@fogarecious fogarecious deleted the add_doc branch February 22, 2024 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants