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

Can not call boxed FnOnce #8

Open
chrysn opened this issue Aug 30, 2023 · 0 comments
Open

Can not call boxed FnOnce #8

chrysn opened this issue Aug 30, 2023 · 0 comments

Comments

@chrysn
Copy link

chrysn commented Aug 30, 2023

Compared to alloc::boxed::Box, this can not be used to run a FnOnce from an owned pointer; it'd be great if that worked.

The test below currently fails to build ("the size of dyn FnOnce() cannot be statically determined"), whereas replacing BoxS with Box (and boxed_s! with Box::new) just works.

We could probably impl<Args> FnOnce(Args) for BoxS<T> where T: FnOnce(Args), but AIU that's blocked by rust-lang/rust#29625. Having a nightly feature would be an option, but given that this crate has worked for years without updates (and nightly features would be a constant whack-a-mole), probably not.

#!/usr/bin/env -S cargo +nightly -Zscript
//! ```cargo
//! [dependencies]
//! no_alloc = "*"
//! ```

use no_alloc::{BoxS, boxed_s};

fn run(f: BoxS<dyn FnOnce() + '_, [usize; 4]>) {
    f()
}

fn main() {
    let v = vec![42];
    let f = || drop(v);
    let b: BoxS<dyn FnOnce() + '_, [usize; 4]> = boxed_s!(f);
    run(b);
}
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