pub struct RawSequence { /* private fields */ }Expand description
A sequence that stores heterogeneous values with proper alignment.
The RawSequence provides a memory-efficient way to store heterogeneous values
while maintaining proper alignment requirements for each type. It uses an
internal buffer that raises its base alignment to satisfy each stored type.
The caller owns destruction of stored values, including before discarding the sequence. Zero-sized values occupy no logical bytes.
§Examples
let mut values = cel_runtime::RawSequence::new();
values.push(String::from("hello"));
assert_eq!(unsafe { values.next::<String>(0) }.0, "hello");
unsafe { values.drop_in_place::<String>(0) };Implementations§
Source§impl RawSequence
impl RawSequence
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty RawSequence.
The sequence initially requests 4096-byte base alignment and raises it
when a stored type requires a wider alignment.
§Examples
let values = cel_runtime::RawSequence::new();
assert!(values.is_empty());Sourcepub fn push<T>(&mut self, value: T)
pub fn push<T>(&mut self, value: T)
Pushes a value onto the sequence.
The value is stored at an address that satisfies its alignment requirements. Automatically grows the internal buffer if needed.
- Complexity: Amortized O(size of
T+ alignment ofT) time and space at an existing base alignment. Raising the base alignment also moves O(n) stored bytes and replaces the buffer allocation.
§Examples
let mut values = cel_runtime::RawSequence::new();
values.push(42u32);
assert_eq!(*unsafe { values.next::<u32>(0) }.0, 42);Sourcepub unsafe fn drop_in_place<T>(&mut self, p: usize) -> usize
pub unsafe fn drop_in_place<T>(&mut self, p: usize) -> usize
Destroys the next value after p and returns the position after it.
§Safety
p must precede a live stored T, with only its alignment padding
between them. The value must not be used or destroyed again.
§Examples
let mut values = cel_runtime::RawSequence::new();
values.push(String::from("owned"));
unsafe { values.drop_in_place::<String>(0) };Sourcepub unsafe fn next<T>(&self, p: usize) -> (&T, usize)
pub unsafe fn next<T>(&self, p: usize) -> (&T, usize)
Retrieves a reference to the next value at the specified position.
§Safety
- The position must point to a valid value of type T
- The caller must ensure that the value is actually of type T
Returns a tuple containing:
- A reference to the value
- The position immediately after the value
§Examples
let mut values = cel_runtime::RawSequence::new();
values.push(42u32);
let (value, next) = unsafe { values.next::<u32>(0) };
assert_eq!((*value, next), (42, 4));