Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // contains simple push/extend logic,
- // no unsafe
- #[repr(C)]
- #[derive(Copy, Clone)]
- struct StackBuffer {
- data: [u8; 23],
- flag: u8
- }
- // For each push/extend, makes a ManualkyDrop<Vec> from the ptr, len and cap.
- // Contains a static method to drop,
- // Uses unsafe
- #[repr(C)]
- #[derive(Copy, Clone)]
- struct HeapBuffer {
- ptr: *mut u8,
- cap: usize,
- len: usize
- }
- // Contains logic
- // thats choses or the heap or the stack
- // for things like push, extend.
- // Contains a static method for Drop,
- // which will only drop if the Heap is used. (Unions cant impl Drop)
- // Uses unsafe for field access
- union Buffer {
- stack: StackBuffer,
- heap: HeapBuffer
- }
- // Delegates every method to its inner field
- struct SmallByteVec {
- inner: Buffer
- }
- // Delegates every method to its inner field
- // Also checks for UTF-8 validness
- pub struct SmallString {
- vec: SmallByteVec
- }
- is...that a good setup ?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement