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

alloc feature ? #73

Open
pwnorbitals opened this issue Sep 15, 2022 · 6 comments
Open

alloc feature ? #73

pwnorbitals opened this issue Sep 15, 2022 · 6 comments

Comments

@pwnorbitals
Copy link

Seeing the crate is no_std, I was tricked into thinking it wouldn’t depend on alloc and would work in my embedded system. A large chunk of embedded systems cannot use a heap for various reasons, so Ouroboros is not compatible with those systems right now.

In the short-term, I suggest adding a warning on the readme saying that, even though the crate is no_std, it still requires alloc to work.

In the longer term, is it viable to expose an alloc feature flag (could be default) that would make Ouroboros compatible with heap-less systems ?

@someguynamedjosh
Copy link
Owner

I have updated the readme to reflect this. Unfortunately, Box<> forms an integral part of the protections the crate provides, so I do not see a way to make the crate work without allocators.

@someguynamedjosh
Copy link
Owner

I will leave this open in case anyone has ideas of how to accomplish this.

@kpreid
Copy link
Contributor

kpreid commented Sep 18, 2022

Some ideas:

  • Perhaps in the future when allocator_api / std::alloc::Allocator is stable, it might be feasible to allow parameterizing an ouroboros object with that and thus allocate self-referential objects in fixed-maximum-size storage rather than the heap.

  • With today's Rust: Use Pin. The non-movable memory would be inlined into the struct rather than a separate allocation, but initialization and access would require a Pin<&mut Self> or some such thing. Unlike the internal Boxes, this would be an externally visible requirement when constructing the object, but that is probably acceptable for no-allocator use cases.

    (I'd like to see a crate that provided safe self-referential structs based on Pin rather than boxing. I doubt extending ouroboros is the best way to do that, but it'd be interesting to have both strategies using as close to equivalent API as possible.)

@pwnorbitals
Copy link
Author

pwnorbitals commented Sep 18, 2022

From discussions today on Rust’s Matrix channel, sebk suggest it could be possible to use relative addressing into the struct to make stack-based self-referential structs work. Actual references would need to be re-computed somehow when user needs access to the values. Not sure how implementable this is, though

@SoniEx2
Copy link

SoniEx2 commented Oct 13, 2022

Shameless self-plug, could also try selfref? It hasn't been as thoroughly tested tho.

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

4 participants