krishvishal commented on code in PR #2944:
URL: https://github.com/apache/iggy/pull/2944#discussion_r2944174530


##########
core/buf/src/lib.rs:
##########
@@ -0,0 +1,381 @@
+use std::mem::ManuallyDrop;
+use std::ptr::NonNull;
+use std::slice;
+use std::sync::atomic::{AtomicUsize, Ordering, fence};
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct Owned {
+    inner: Vec<u8>,
+}
+
+#[derive(Clone, Copy)]
+struct Half {
+    ptr: NonNull<u8>,
+    len: usize,
+    ctrlb: NonNull<ControlBlock>,
+}
+
+struct ControlBlock {
+    ref_count: AtomicUsize,
+    base: NonNull<u8>,
+    len: usize,
+    cap: usize,
+}
+
+fn create_control_block(base: NonNull<u8>, len: usize, cap: usize) -> 
NonNull<ControlBlock> {
+    let ctrlb = Box::new(ControlBlock {
+        ref_count: AtomicUsize::new(1),
+        base,
+        len,
+        cap,
+    });
+    // SAFETY: `ctrlb` is a valid control block for the lifetime of the 
returned halves.
+    unsafe { NonNull::new_unchecked(Box::into_raw(ctrlb)) }
+}
+
+pub struct TwoHalves {

Review Comment:
   Is `TwoHalves` made for representing mutable header and immutable body? 
   
   If yes, I think naming `HeaderBody` or something similar makes the intention 
more clear. Because I find `TwoHalves` more abstract and makes it hard to 
understand what it is for.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to