Function alignInSlice [src]

Returns the largest sub-slice within the given slice that conforms to the new alignment, or null if the given slice contains no conforming address.

Prototype

pub fn alignInSlice(slice: anytype, comptime new_alignment: usize) ?AlignedSlice(@TypeOf(slice), new_alignment)

Parameters

new_alignment: usize

Source

pub fn alignInSlice(slice: anytype, comptime new_alignment: usize) ?AlignedSlice(@TypeOf(slice), new_alignment) { const bytes = sliceAsBytes(slice); const aligned_bytes = alignInBytes(bytes, new_alignment) orelse return null; const Element = @TypeOf(slice[0]); const slice_length_bytes = aligned_bytes.len - (aligned_bytes.len % @sizeOf(Element)); const aligned_slice = bytesAsSlice(Element, aligned_bytes[0..slice_length_bytes]); return @alignCast(aligned_slice); }