Advertisement
Guest User

Untitled

a guest
Sep 13th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.94 KB | None | 0 0
  1. // contains simple push/extend logic,
  2. // no unsafe
  3. #[repr(C)]
  4. #[derive(Copy, Clone)]
  5. struct StackBuffer {
  6.     data: [u8; 23],
  7.     flag: u8
  8. }
  9.  
  10. // For each push/extend, makes a ManualkyDrop<Vec> from the ptr, len and cap.
  11. // Contains a static method to drop,
  12. // Uses unsafe
  13. #[repr(C)]
  14. #[derive(Copy, Clone)]
  15. struct HeapBuffer {
  16.     ptr: *mut u8,
  17.     cap: usize,
  18.     len: usize
  19. }
  20.  
  21. // Contains logic
  22. // thats choses or the heap or the stack
  23. // for things like push, extend.
  24. // Contains a static method for Drop,
  25. // which will only drop if the Heap is used. (Unions cant impl Drop)
  26. // Uses unsafe for field access
  27. union Buffer {
  28.     stack: StackBuffer,
  29.     heap: HeapBuffer
  30. }
  31.  
  32. // Delegates every method to its inner field
  33. struct SmallByteVec {
  34.     inner: Buffer
  35. }
  36.  
  37. // Delegates every method to its inner field
  38. // Also checks for UTF-8 validness
  39. pub struct SmallString {
  40.     vec: SmallByteVec
  41. }
  42.  
  43.  
  44. is...that a good setup ?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement