Skip to content

use alloc::boxed::Box instead of the builtin Box#296

Closed
NikoPit wants to merge 5 commits into
dtolnay:masterfrom
NikoPit:master
Closed

use alloc::boxed::Box instead of the builtin Box#296
NikoPit wants to merge 5 commits into
dtolnay:masterfrom
NikoPit:master

Conversation

@NikoPit
Copy link
Copy Markdown

@NikoPit NikoPit commented May 8, 2026

uses alloc::boxed::Box instead of Box
this ensures that this crate works on no_std environment

fixes #295

@NikoPit
Copy link
Copy Markdown
Author

NikoPit commented May 8, 2026

aparently that broke std, im working on fixing that

@NikoPit
Copy link
Copy Markdown
Author

NikoPit commented May 8, 2026

now it was fixed

Copy link
Copy Markdown

@A4-Tacks A4-Tacks left a comment

Choose a reason for hiding this comment

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

As a proc-macro library, no_std should be meaningless

@NikoPit
Copy link
Copy Markdown
Author

NikoPit commented May 8, 2026

not really, check #295 , its generated codes refrences Box directly instead of alloc::boxed::Box, which doesnt work in no_std environment

@A4-Tacks
Copy link
Copy Markdown

A4-Tacks commented May 8, 2026

There is a method similar to extern crate alloc as std here

And introducing new alloc feature doesn't seem necessary

@NikoPit
Copy link
Copy Markdown
Author

NikoPit commented May 8, 2026

when i just do alloc::boxed::Box it just breaks std environment, and i cant really find a better way then using a feature (since there is no things like #[cfg(no_std)])

@A4-Tacks
Copy link
Copy Markdown

A4-Tacks commented May 8, 2026

Part of the code can be expanded to {extern crate alloc; alloc::boxed::Box::...}

But your PR is still breaking, because different dependencies in workspace will union features, which may potentially disrupt dependencies

Like:

  • crate foo dependencies async-trait
  • crate bar dependencies async-trait features alloc

So async-trait enable alloc in foo and bar, breaking in crate foo

@A4-Tacks
Copy link
Copy Markdown

A4-Tacks commented May 8, 2026

In summary, the old code works well and does not require consideration of absolute paths.
Users only need to import Box

And consider the possibility of use Arc as Box

@NikoPit
Copy link
Copy Markdown
Author

NikoPit commented May 8, 2026

well thats basically the problem, the user isnt supposed to import Box, the crate should do it (atleast imo)

@NikoPit
Copy link
Copy Markdown
Author

NikoPit commented May 8, 2026

ok i realized im dumb or smth, closing ig

@NikoPit NikoPit closed this May 8, 2026
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

Successfully merging this pull request may close these issues.

Can not find 'Box' on no_std environments

2 participants