Skip to content

Possibly reducing boilerplate. #19

@Swoorup

Description

@Swoorup

Thanks for this awesome crate.

Instead of init2, init or try_* or even pin_* variant, is it possible for the macro to just generate a particular variant? I think you usually tend to just just one kind of constructor throughout the codebase?

#[dynify::dynify(init2)]
trait AsyncRead { // By default, another trait prefixed with `Dyn` is generated.
    async fn read_to_string(&mut self) -> String;
}


async fn dynamic_dispatch(reader: &mut dyn DynAsyncRead) {
    let content = reader.read_to_string().await;

    /*  The above will do behind the scenes this.
    let mut stack = [MaybeUninit::<u8>::uninit(); 16];
    let mut heap = Vec::<MaybeUninit<u8>>::new();
    // Initialize trait objects on the stack if not too large, otherwise on the heap.
    let fut = reader.read_to_string().init2(&mut stack, &mut heap); 
    */
}

Metadata

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