Struct tvix_eval::value::string::NixStringInner

source ·
struct NixStringInner {
    context: Option<Box<NixContext>>,
    length: usize,
    data: [u8],
}
Expand description

This type is never instantiated, but serves to document the memory layout of the actual heap allocation for Nix strings.

Fields§

§context: Option<Box<NixContext>>

The string context, if any. Note that this is boxed to take advantage of the null pointer niche, otherwise this field ends up being very large:

>> std::mem::size_of::<Option<HashSet<String>>>()
48

>> std::mem::size_of::<Option<Box<HashSet<String>>>>()
8
§length: usize

The length of the data, stored inline in the allocation

§data: [u8]

The actual data for the string itself. Will always be length bytes long

Implementations§

source§

impl NixStringInner

source

fn layout(len: usize) -> (Layout, usize, usize)

Construct a Layout for a nix string allocation with the given length.

Returns a tuple of:

  1. The layout itself.
  2. The offset of Self::length within the allocation, assuming the allocation starts at 0
  3. The offset of the data array within the allocation, assuming the allocation starts at 0
source

unsafe fn layout_of(this: NonNull<c_void>) -> (Layout, usize, usize)

Returns the Layout for an already-allocated nix string, loading the length from the pointer.

Returns a tuple of:

  1. The layout itself.
  2. The offset of Self::length within the allocation, assuming the allocation starts at 0
  3. The offset of the data array within the allocation, assuming the allocation starts at 0
§Safety

This function must only be called on a pointer that has been properly initialized with Self::alloc. The data buffer may not necessarily be initialized

source

fn alloc(len: usize) -> NonNull<c_void>

Allocate an uninitialized nix string with the given length. Writes the length to the length value in the pointer, but leaves both context and data uninitialized

This function is safe to call (as constructing pointers of any sort of validity is always safe in Rust) but it is unsafe to use the resulting pointer to do anything other than

  1. Read the length
  2. Write the context
  3. Write the data

until the string is fully initialized

source

unsafe fn dealloc(this: NonNull<c_void>)

Deallocate the Nix string at the given pointer

§Safety

This function must only be called with a pointer that has been properly initialized with Self::alloc

source

unsafe fn len(this: NonNull<c_void>) -> usize

Return the length of the Nix string at the given pointer

§Safety

This function must only be called with a pointer that has been properly initialized with Self::alloc

source

unsafe fn context_ptr(this: NonNull<c_void>) -> *mut Option<Box<NixContext>>

Return a pointer to the context value within the given Nix string pointer

§Safety

This function must only be called with a pointer that has been properly initialized with Self::alloc

source

unsafe fn context_ref<'a>(this: NonNull<c_void>) -> &'a Option<Box<NixContext>>

Construct a shared reference to the context value within the given Nix string pointer

§Safety

This function must only be called with a pointer that has been properly initialized with Self::alloc, and where the context has been properly initialized (by writing to the pointer returned from Self::context_ptr).

Also, all the normal Rust rules about pointer-to-reference conversion apply. See NonNull::as_ref for more.

source

unsafe fn context_mut<'a>( this: NonNull<c_void>, ) -> &'a mut Option<Box<NixContext>>

Construct a mutable reference to the context value within the given Nix string pointer

§Safety

This function must only be called with a pointer that has been properly initialized with Self::alloc, and where the context has been properly initialized (by writing to the pointer returned from Self::context_ptr).

Also, all the normal Rust rules about pointer-to-reference conversion apply. See NonNull::as_mut for more.

source

unsafe fn data_ptr(this: NonNull<c_void>) -> *mut u8

Return a pointer to the data array within the given Nix string pointer

§Safety

This function must only be called with a pointer that has been properly initialized with Self::alloc

source

unsafe fn data_slice<'a>(this: NonNull<c_void>) -> &'a [u8]

Construct a shared reference to the data slice within the given Nix string pointer

§Safety

This function must only be called with a pointer that has been properly initialized with Self::alloc, and where the data array has been properly initialized (by writing to the pointer returned from Self::data_ptr).

Also, all the normal Rust rules about pointer-to-reference conversion apply. See slice::from_raw_parts for more.

source

unsafe fn data_slice_mut<'a>(this: NonNull<c_void>) -> &'a mut [u8]

Construct a mutable reference to the data slice within the given Nix string pointer

§Safety

This function must only be called with a pointer that has been properly initialized with Self::alloc, and where the data array has been properly initialized (by writing to the pointer returned from Self::data_ptr).

Also, all the normal Rust rules about pointer-to-reference conversion apply. See slice::from_raw_parts_mut for more.

source

unsafe fn clone(this: NonNull<c_void>) -> NonNull<c_void>

Clone the Nix string pointed to by this pointer, and return a pointer to a new Nix string containing the same data and context.

§Safety

This function must only be called with a pointer that has been properly initialized with Self::alloc, and where the context has been properly initialized (by writing to the pointer returned from Self::context_ptr), and the data array has been properly initialized (by writing to the pointer returned from Self::data_ptr).

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more