Box like value in struct in no_std context

34 views Asked by At

I'm trying to move over the core part of a library to use no_std.

Essentially an important new type is this:

struct Packets(Box<[Packet]>);

This way it's ensured Packets can be stored in a way to ensures it's continuous in memory and the impl block of this struct provides a few important methods. Now in a no_std context I cannot use Box. Is there some struct which allows a struct to hold an owned slice of data?

Edit:

My question is NOT that I want to use box in a no_std context. I need a subset of the features Box provides (Namely storing an owned piece of data in a Struct, nothing else). I don't want to include allocation, because I'm not looking to allocate anything.

A bad way to achieve what I want is to store a length and a raw pointer in the struct

 Packets{ len: usize, ptr: *mut Packet } 

This way I can write my impl block and let used choose how they want allocate. It sucks a lot though because of unsafe usage, manual memory management and in general I don't want pointers for something that, morally, should be possible with a normal language construct.

0

There are 0 answers