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
impl NixStringInner
sourcefn layout(len: usize) -> (Layout, usize, usize)
fn layout(len: usize) -> (Layout, usize, usize)
Construct a Layout
for a nix string allocation with the given length.
Returns a tuple of:
- The layout itself.
- The offset of
Self::length
within the allocation, assuming the allocation starts at 0 - The offset of the data array within the allocation, assuming the allocation starts at 0
sourceunsafe fn layout_of(this: NonNull<c_void>) -> (Layout, usize, usize)
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:
- The layout itself.
- The offset of
Self::length
within the allocation, assuming the allocation starts at 0 - 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
sourcefn alloc(len: usize) -> NonNull<c_void>
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
- Read the length
- Write the context
- Write the data
until the string is fully initialized
sourceunsafe fn dealloc(this: NonNull<c_void>)
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
sourceunsafe fn len(this: NonNull<c_void>) -> usize
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
sourceunsafe fn context_ptr(this: NonNull<c_void>) -> *mut Option<Box<NixContext>>
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
sourceunsafe fn context_ref<'a>(this: NonNull<c_void>) -> &'a Option<Box<NixContext>>
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.
sourceunsafe fn context_mut<'a>(
this: NonNull<c_void>,
) -> &'a mut Option<Box<NixContext>>
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.
sourceunsafe fn data_ptr(this: NonNull<c_void>) -> *mut u8
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
sourceunsafe fn data_slice<'a>(this: NonNull<c_void>) -> &'a [u8] ⓘ
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.
sourceunsafe fn data_slice_mut<'a>(this: NonNull<c_void>) -> &'a mut [u8] ⓘ
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.
sourceunsafe fn clone(this: NonNull<c_void>) -> NonNull<c_void>
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
).