Skip to content

Manually type the outputs of a generator using gen! #26

Open
@philip-peterson

Description

Hi there,

I am wanting to have a generator that will yield values that are an Rc<dyn T>. Currently I have to do it like so:

async fn produce_pages(mut co: Co<'_, Rc<dyn GeneratedPage>>) {
    co.yield_(Rc::new(HomePage {})).await;
    co.yield_(Rc::new(ContactPage {})).await;
}

fn foo() -> () {
    let_gen_using!(gen_all_pages, produce);
    gen_all_pages.into_iter().collect();
}

This means that foo cannot return the iterator sadly because of the use of let_gen_using, which leaks the shelf value which is owned by the foo function.

The whole reason I need to use the producer pattern is because gen!() doesn't accept a type argument (which is needed because of the dyn); would it be possible to have it allow a field that specifies what type the Rust compiler should know the generator results to be?

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions