pub fn absorbSentinel(slice: anytype) AbsorbSentinel(@TypeOf(slice))
If the provided slice is not sentinel terminated, do nothing and return that slice.
- Kind
- function
- Module
std.mem
pub fn alignBackward(comptime T: type, addr: T, alignment: T) T
Round an address down to the previous (or current) aligned address.
- Kind
- function
- Module
std.mem
pub fn alignBackwardAnyAlign(comptime T: type, addr: T, alignment: T) T
Round an address down to the previous (or current) aligned address.
- Kind
- function
- Module
std.mem
pub fn alignForward(comptime T: type, addr: T, alignment: T) T
Round an address up to the next (or current) aligned address.
- Kind
- function
- Module
std.mem
pub fn alignForwardAnyAlign(comptime T: type, addr: T, alignment: T) T
Round an address down to the next (or current) aligned address.
- Kind
- function
- Module
std.mem
pub fn alignForwardLog2(addr: usize, log2_alignment: u8) usize
Rounds an address up to the next alignment boundary using log2 representation.
- Kind
- function
- Module
std.mem
pub fn alignInBytes(bytes: []u8, comptime new_alignment: usize) ?[]align(new_alignment) u8
Returns the largest slice in the given bytes that conforms to the new alignment, or `null` if the given bytes contain no conforming address.
- Kind
- function
- Module
std.mem
pub fn alignInSlice(slice: anytype, comptime new_alignment: usize) ?AlignedSlice(@TypeOf(slice), new_alignment)
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.
- Kind
- function
- Module
std.mem
Stored as a power-of-two.
- Kind
- enum
- Module
std.mem
pub fn backward(a: Alignment, address: usize) usize
Return previous address with this alignment.
- Kind
- function
- Module
std.mem
pub fn check(a: Alignment, address: usize) bool
Return whether address is aligned to this amount.
- Kind
- function
- Module
std.mem
pub fn compare(lhs: Alignment, op: std.math.CompareOperator, rhs: Alignment) bool
- Kind
- function
- Module
std.mem
pub fn forward(a: Alignment, address: usize) usize
Return next address with this alignment.
- Kind
- function
- Module
std.mem
pub fn fromByteUnits(n: usize) Alignment
- Kind
- function
- Module
std.mem
pub fn fromByteUnitsOptional(maybe_n: ?usize) ?Alignment
- Kind
- function
- Module
std.mem
pub fn max(lhs: Alignment, rhs: Alignment) Alignment
- Kind
- function
- Module
std.mem
pub fn min(lhs: Alignment, rhs: Alignment) Alignment
- Kind
- function
- Module
std.mem
pub fn of(comptime T: type) Alignment
- Kind
- function
- Module
std.mem
pub fn order(lhs: Alignment, rhs: Alignment) std.math.Order
- Kind
- function
- Module
std.mem
pub fn toByteUnits(a: Alignment) usize
- Kind
- function
- Module
std.mem
pub fn alignPointer(ptr: anytype, align_to: usize) ?@TypeOf(ptr)
Aligns a given pointer value to a specified alignment factor.
- Kind
- function
- Module
std.mem
pub fn alignPointerOffset(ptr: anytype, align_to: usize) ?usize
- Kind
- function
- Module
std.mem
pub fn allEqual(comptime T: type, slice: []const T, scalar: T) bool
Returns true if all elements in a slice are equal to the scalar value provided.
- Kind
- function
- Module
std.mem
- Kind
- struct
- Module
std.mem
pub fn asBytes(ptr: anytype) AsBytesReturnType(@TypeOf(ptr))
Given a pointer to a single item, returns a slice of the underlying bytes, preserving pointer attributes.
- Kind
- function
- Module
std.mem
pub fn bigToNative(comptime T: type, x: T) T
Converts a big-endian integer to host endianness.
- Kind
- function
- Module
std.mem
pub fn boundedOrderZ(comptime T: type, lhs: [*:0]const T, rhs: [*:0]const T, bound: usize) math.Order
Compares two many-item pointers with NUL-termination lexicographically until some specified bound.
- Kind
- function
- Module
std.mem
The standard library currently thoroughly depends on byte size being 8 bits. (see the use of u8 throughout allocation code as the "byte" type.) Code which depends on this can reference this declaration.
- Kind
- constant
- Module
std.mem
pub fn bytesAsSlice(comptime T: type, bytes: anytype) BytesAsSliceReturnType(T, @TypeOf(bytes))
Given a slice of bytes, returns a slice of the specified type backed by those bytes, preserving pointer attributes.
- Kind
- function
- Module
std.mem
pub fn bytesAsValue(comptime T: type, bytes: anytype) BytesAsValueReturnType(T, @TypeOf(bytes))
Given a pointer to an array of bytes, returns a pointer to a value of the specified type backed by those bytes, preserving pointer attributes.
- Kind
- function
- Module
std.mem
pub fn bytesToValue(comptime T: type, bytes: anytype) T
Given a pointer to an array of bytes, returns a value of the specified type backed by a copy of those bytes.
- Kind
- function
- Module
std.mem
pub fn byteSwap(comptime S: type, ptr: *S) void
Reverses the byte order.
- Kind
- function
- Module
std.mem
pub fn byteSwapAligned(comptime S: type, comptime a: Alignment, ptr: *align(a.toByteUnits()) S) void
Reverses the byte order.
- Kind
- function
- Module
std.mem
pub fn byteSwapAllElements(comptime Elem: type, slice: []Elem) void
Reverses the byte order of all elements in a slice.
- Kind
- function
- Module
std.mem
pub fn collapseRepeats(comptime T: type, slice: []T, elem: T) []T
Collapse consecutive duplicate elements into one entry.
- Kind
- function
- Module
std.mem
pub fn collapseRepeatsLen(comptime T: type, slice: []T, elem: T) usize
Collapse consecutive duplicate elements into one entry.
- Kind
- function
- Module
std.mem
pub fn concat(allocator: Allocator, comptime T: type, slices: []const []const T) Allocator.Error![]T
Copies each T from slices into a new slice that exactly holds all the elements.
- Kind
- function
- Module
std.mem
pub fn concatMaybeSentinel(allocator: Allocator, comptime T: type, slices: []const []const T, comptime s: ?T) Allocator.Error![]T
Copies each T from slices into a new slice that exactly holds all the elements as well as the sentinel.
- Kind
- function
- Module
std.mem
pub fn concatWithSentinel(allocator: Allocator, comptime T: type, slices: []const []const T, comptime s: T) Allocator.Error![:s]T
Copies each T from slices into a new slice that exactly holds all the elements.
- Kind
- function
- Module
std.mem
pub fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: usize, needle: []const T) bool
- Kind
- function
- Module
std.mem
pub fn containsAtLeastScalar(comptime T: type, list: []const T, element: T, minimum: usize) bool
Related: * `containsAtLeast` * `countScalar`.
- Kind
- function
- Module
std.mem
pub fn copyBackwards(comptime T: type, dest: []T, source: []const T) void
Copy all of source into dest at position 0. dest.len must be >= source.len.
- Kind
- function
- Module
std.mem
pub fn copyForwards(comptime T: type, dest: []T, source: []const T) void
Copy all of source into dest at position 0. dest.len must be >= source.len.
- Kind
- function
- Module
std.mem
pub fn copySentinel(comptime T: type, comptime s: T, dest: []T, source: [*:s]const T) usize
Copy `source` into `dest`, excluding the sentinel.
- Kind
- function
- Module
std.mem
pub fn copySentinelInclusive(comptime T: type, comptime s: T, dest: []T, source: [*:s]const T) usize
Copy `source` into `dest`, including the sentinel.
- Kind
- function
- Module
std.mem
pub fn count(comptime T: type, haystack: []const T, needle: []const T) usize
Returns the number of needles inside the haystack needle.len must be > 0 does not count overlapping needles.
- Kind
- function
- Module
std.mem
pub fn countScalar(comptime T: type, list: []const T, element: T) usize
Returns the number of times `element` appears in a slice of memory.
- Kind
- function
- Module
std.mem
pub fn cut(comptime T: type, haystack: []const T, needle: []const T) ?struct
Returns slice of `haystack` before and after first occurrence of `needle`, or `null` if not found.
- Kind
- function
- Module
std.mem
pub fn cutLast(comptime T: type, haystack: []const T, needle: []const T) ?struct
Returns slice of `haystack` before and after last occurrence of `needle`, or `null` if not found.
- Kind
- function
- Module
std.mem
pub fn cutPrefix(comptime T: type, slice: []const T, prefix: []const T) ?[]const T
If `slice` starts with `prefix`, returns the rest of `slice` starting at `prefix.len`.
- Kind
- function
- Module
std.mem
pub fn cutScalar(comptime T: type, haystack: []const T, needle: T) ?struct
Returns slice of `haystack` before and after first occurrence `needle`, or `null` if not found.
- Kind
- function
- Module
std.mem
pub fn cutScalarLast(comptime T: type, haystack: []const T, needle: T) ?struct
Returns slice of `haystack` before and after last occurrence of `needle`, or `null` if not found.
- Kind
- function
- Module
std.mem
pub fn cutSuffix(comptime T: type, slice: []const T, suffix: []const T) ?[]const T
If `slice` ends with `suffix`, returns `slice` from beginning to start of `suffix`.
- Kind
- function
- Module
std.mem
Delimiter type for tokenization and splitting operations.
- Kind
- type
- Module
std.mem
pub fn doNotOptimizeAway(val: anytype) void
- Kind
- function
- Module
std.mem
pub fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool
Returns true if haystack ends with needle.
- Kind
- function
- Module
std.mem
pub fn eql(comptime T: type, a: []const T, b: []const T) bool
Returns true if and only if the slices have the same length and all elements compare true using equality operator.
- Kind
- function
- Module
std.mem
pub fn find(comptime T: type, haystack: []const T, needle: []const T) ?usize
Search for needle in haystack and return the index of the first occurrence.
- Kind
- function
- Module
std.mem
pub fn findAny(comptime T: type, slice: []const T, values: []const T) ?usize
Linear search for the index of any value in the provided list inside a slice.
- Kind
- function
- Module
std.mem
pub fn findAnyPos(comptime T: type, slice: []const T, start_index: usize, values: []const T) ?usize
Linear search for the index of any value in the provided list inside a slice, starting from a given position.
- Kind
- function
- Module
std.mem
pub fn findDiff(comptime T: type, a: []const T, b: []const T) ?usize
Compares two slices and returns the index of the first inequality.
- Kind
- function
- Module
std.mem
pub fn findLast(comptime T: type, haystack: []const T, needle: []const T) ?usize
Find the index in a slice of a sub-slice, searching from the end backwards.
- Kind
- function
- Module
std.mem
pub fn findLastAny(comptime T: type, slice: []const T, values: []const T) ?usize
Linear search for the last index of any value in the provided list inside a slice.
- Kind
- function
- Module
std.mem
pub fn findLastLinear(comptime T: type, haystack: []const T, needle: []const T) ?usize
Find the index in a slice of a sub-slice, searching from the end backwards.
- Kind
- function
- Module
std.mem
pub fn findLastNone(comptime T: type, slice: []const T, values: []const T) ?usize
Find the last item in `slice` which is not contained in `values`.
- Kind
- function
- Module
std.mem
pub fn findMax(comptime T: type, slice: []const T) usize
Returns the index of the largest number in a slice.
- Kind
- function
- Module
std.mem
pub fn findMin(comptime T: type, slice: []const T) usize
Returns the index of the smallest number in a slice.
- Kind
- function
- Module
std.mem
pub fn findMinMax(comptime T: type, slice: []const T) struct
Finds the indices of the smallest and largest number in a slice.
- Kind
- function
- Module
std.mem
pub fn findNone(comptime T: type, slice: []const T, values: []const T) ?usize
Find the first item in `slice` which is not contained in `values`.
- Kind
- function
- Module
std.mem
pub fn findNonePos(comptime T: type, slice: []const T, start_index: usize, values: []const T) ?usize
Find the first item in `slice[start_index..]` which is not contained in `values`.
- Kind
- function
- Module
std.mem
pub fn findPos(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) ?usize
Uses Boyer-Moore-Horspool algorithm on large inputs; `findPosLinear` on small inputs.
- Kind
- function
- Module
std.mem
pub fn findPosLinear(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) ?usize
Consider using `findPos` instead of this, which will automatically use a more sophisticated algorithm on larger inputs.
- Kind
- function
- Module
std.mem
pub fn findScalar(comptime T: type, slice: []const T, value: T) ?usize
Linear search for the index of a scalar value inside a slice.
- Kind
- function
- Module
std.mem
pub fn findScalarLast(comptime T: type, slice: []const T, value: T) ?usize
Linear search for the last index of a scalar value inside a slice.
- Kind
- function
- Module
std.mem
pub fn findScalarPos(comptime T: type, slice: []const T, start_index: usize, value: T) ?usize
Linear search for the index of a scalar value inside a slice, starting from a given position.
- Kind
- function
- Module
std.mem
pub fn findSentinel(comptime T: type, comptime sentinel: T, p: [*:sentinel]const T) usize
Returns the index of the sentinel value in a sentinel-terminated pointer.
- Kind
- function
- Module
std.mem
- Kind
- constant
- Module
std.mem
- Kind
- constant
- Module
std.mem
- Kind
- constant
- Module
std.mem
pub fn isAligned(addr: usize, alignment: usize) bool
Given an address and an alignment, return true if the address is a multiple of the alignment The alignment must be a power of 2 and greater than 0.
- Kind
- function
- Module
std.mem
pub fn isAlignedAnyAlign(i: usize, alignment: usize) bool
Returns true if i is aligned to the given alignment.
- Kind
- function
- Module
std.mem
pub fn isAlignedGeneric(comptime T: type, addr: T, alignment: T) bool
Generic version of `isAligned` that works with any integer type.
- Kind
- function
- Module
std.mem
pub fn isAlignedLog2(addr: usize, log2_alignment: u8) bool
Returns true if addr is aligned to 2^log2_alignment.
- Kind
- function
- Module
std.mem
pub fn isValidAlign(alignment: usize) bool
Returns whether `alignment` is a valid alignment, meaning it is a positive power of 2.
- Kind
- function
- Module
std.mem
pub fn isValidAlignGeneric(comptime T: type, alignment: T) bool
Returns whether `alignment` is a valid alignment, meaning it is a positive power of 2.
- Kind
- function
- Module
std.mem
pub fn join(allocator: Allocator, separator: []const u8, slices: []const []const u8) Allocator.Error![]u8
Naively combines a series of slices with a separator.
- Kind
- function
- Module
std.mem
pub fn joinZ(allocator: Allocator, separator: []const u8, slices: []const []const u8) Allocator.Error![:0]u8
Naively combines a series of slices with a separator and null terminator.
- Kind
- function
- Module
std.mem
pub fn len(value: anytype) usize
Takes a sentinel-terminated pointer and iterates over the memory to find the sentinel and determine the length. `[*c]` pointers are assumed to be non-null and 0-terminated.
- Kind
- function
- Module
std.mem
pub fn lessThan(comptime T: type, lhs: []const T, rhs: []const T) bool
Returns true if lhs < rhs, false otherwise.
- Kind
- function
- Module
std.mem
pub fn lessThanZ(comptime T: type, lhs: [*:0]const T, rhs: [*:0]const T) bool
Returns `true` if `lhs < rhs`; `false` otherwise, operating on null-terminated arrays.
- Kind
- function
- Module
std.mem
pub fn littleToNative(comptime T: type, x: T) T
Converts a little-endian integer to host endianness.
- Kind
- function
- Module
std.mem
pub fn max(comptime T: type, slice: []const T) T
Returns the largest number in a slice.
- Kind
- function
- Module
std.mem
pub fn min(comptime T: type, slice: []const T) T
Returns the smallest number in a slice.
- Kind
- function
- Module
std.mem
pub fn minMax(comptime T: type, slice: []const T) struct
Finds the smallest and largest number in a slice.
- Kind
- function
- Module
std.mem
pub fn nativeTo(comptime T: type, x: T, desired_endianness: Endian) T
Converts an integer which has host endianness to the desired endianness.
- Kind
- function
- Module
std.mem
pub fn nativeToBig(comptime T: type, x: T) T
Converts an integer which has host endianness to big endian.
- Kind
- function
- Module
std.mem
pub fn nativeToLittle(comptime T: type, x: T) T
Converts an integer which has host endianness to little endian.
- Kind
- function
- Module
std.mem
pub fn order(comptime T: type, lhs: []const T, rhs: []const T) math.Order
Compares two slices of numbers lexicographically.
- Kind
- function
- Module
std.mem
pub fn orderZ(comptime T: type, lhs: [*:0]const T, rhs: [*:0]const T) math.Order
Compares two many-item pointers with NUL-termination lexicographically.
- Kind
- function
- Module
std.mem
pub fn print(buffer: []u8, comptime format: []const u8, args: anytype) PrintError![]u8
Render a formatted string into `buffer`.
- Kind
- function
- Module
std.mem
- Kind
- error set
- Module
std.mem
pub fn printSentinel(buffer: []u8, comptime format: []const u8, args: anytype, comptime sentinel: u8) PrintError![:sentinel]u8
Like `print` but returned slice has the provided sentinel.
- Kind
- function
- Module
std.mem
pub fn readInt(comptime T: type, buffer: *const [@divExact(@typeInfo(T).int.bits, 8)]u8, endian: Endian) T
Reads an integer from memory with bit count specified by T. The bit count of T must be evenly divisible by 8.
- Kind
- function
- Module
std.mem
pub fn readPackedInt(comptime T: type, bytes: []const u8, bit_offset: usize, endian: Endian) T
Loads an integer from packed memory.
- Kind
- function
- Module
std.mem
pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: Endian) ReturnType
Reads an integer from memory with size equal to bytes.len.
- Kind
- function
- Module
std.mem
pub fn readVarPackedInt(comptime T: type, bytes: []const u8, bit_offset: usize, bit_count: usize, endian: std.builtin.Endian, signedness: std.builtin.Signedness) T
Loads an integer from packed memory with provided bit_count, bit_offset, and signedness.
- Kind
- function
- Module
std.mem
pub fn replace(comptime T: type, input: []const T, needle: []const T, replacement: []const T, output: []T) usize
Replace needle with replacement as many times as possible, writing to an output buffer which is assumed to be of appropriate size.
- Kind
- function
- Module
std.mem
pub fn replacementSize(comptime T: type, input: []const T, needle: []const T, replacement: []const T) usize
Calculate the size needed in an output buffer to perform a replacement.
- Kind
- function
- Module
std.mem
pub fn replaceOwned(comptime T: type, allocator: Allocator, input: []const T, needle: []const T, replacement: []const T) Allocator.Error![]T
Perform a replacement on an allocated buffer of pre-determined size.
- Kind
- function
- Module
std.mem
pub fn replaceScalar(comptime T: type, slice: []T, match: T, replacement: T) void
Replace all occurrences of `match` with `replacement`.
- Kind
- function
- Module
std.mem
pub fn reverse(comptime T: type, items: []T) void
In-place order reversal of a slice.
- Kind
- function
- Module
std.mem
pub fn ReverseIterator(comptime T: type) type
Returned by `reverseIterator`.
- Kind
- type function
- Module
std.mem
pub fn reverseIterator(slice: anytype) ReverseIterator(@TypeOf(slice))
Iterates over a slice in reverse.
- Kind
- function
- Module
std.mem
pub fn next(self: *@This()) ?Element
- Kind
- function
- Module
std.mem
pub fn nextPtr(self: *@This()) ?ElementPointer
- Kind
- function
- Module
std.mem
pub fn rotate(comptime T: type, items: []T, amount: usize) void
In-place rotation of the values in an array ([0 1 2 3] becomes [1 2 3 0] if we rotate by 1) Assumes 0 <= amount <= items.len.
- Kind
- function
- Module
std.mem
pub fn sliceAsBytes(slice: anytype) SliceAsBytesReturnType(@TypeOf(slice))
Given a slice, returns a slice of the underlying bytes, preserving pointer attributes.
- Kind
- function
- Module
std.mem
pub fn sliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) SliceTo(@TypeOf(ptr), end)
Takes a pointer to an array, a many-item pointer, or a slice, and returns a slice of the items up to the first occurrence of `end`.
- Kind
- function
- Module
std.mem
pub fn sort(comptime T: type, items: []T, context: anytype, comptime lessThanFn: fn (@TypeOf(context), lhs: T, rhs: T) bool) void
Sorts a slice in-place using a stable algorithm (maintains relative order of equal elements).
- Kind
- function
- Module
std.mem
pub fn sortContext(a: usize, b: usize, context: anytype) void
- Kind
- function
- Module
std.mem
pub fn sortUnstable(comptime T: type, items: []T, context: anytype, comptime lessThanFn: fn (@TypeOf(context), lhs: T, rhs: T) bool) void
Sorts a slice in-place using an unstable algorithm (does not preserve relative order of equal elements).
- Kind
- function
- Module
std.mem
pub fn sortUnstableContext(a: usize, b: usize, context: anytype) void
Sorts a range [a, b) using an unstable algorithm with custom context.
- Kind
- function
- Module
std.mem
pub fn span(ptr: anytype) Span(@TypeOf(ptr))
Takes a sentinel-terminated pointer and returns a slice, iterating over the memory to find the sentinel and determine the length.
- Kind
- function
- Module
std.mem
pub fn splitAny(comptime T: type, buffer: []const T, delimiters: []const T) SplitIterator(T, .any)
Returns an iterator that iterates over the slices of `buffer` that are separated by any item in `delimiters`. `splitAny(u8, "abc,def||ghi", "|,")` will return slices for "abc", "def", "", "ghi", null, in that order.
- Kind
- function
- Module
std.mem
pub fn splitBackwardsAny(comptime T: type, buffer: []const T, delimiters: []const T) SplitBackwardsIterator(T, .any)
Returns an iterator that iterates backwards over the slices of `buffer` that are separated by any item in `delimiters`. `splitBackwardsAny(u8, "abc,def||ghi", "|,")` will return slices for "ghi", "", "def", "abc", null, in that order.
- Kind
- function
- Module
std.mem
pub fn SplitBackwardsIterator(comptime T: type, comptime delimiter_type: DelimiterType) type
Iterator type for splitting operations from the end backwards, including empty sequences.
- Kind
- type function
- Module
std.mem
pub fn first(self: *Self) []const T
Returns a slice of the first field.
- Kind
- function
- Module
std.mem
pub fn next(self: *Self) ?[]const T
Returns a slice of the next field, or null if splitting is complete.
- Kind
- function
- Module
std.mem
pub fn reset(self: *Self) void
Resets the iterator to the initial slice.
- Kind
- function
- Module
std.mem
pub fn rest(self: Self) []const T
Returns a slice of the remaining bytes.
- Kind
- function
- Module
std.mem
pub fn splitBackwardsScalar(comptime T: type, buffer: []const T, delimiter: T) SplitBackwardsIterator(T, .scalar)
Returns an iterator that iterates backwards over the slices of `buffer` that are separated by `delimiter`. `splitBackwardsScalar(u8, "abc|def||ghi", '|')` will return slices for "ghi", "", "def", "abc", null, in that order.
- Kind
- function
- Module
std.mem
pub fn splitBackwardsSequence(comptime T: type, buffer: []const T, delimiter: []const T) SplitBackwardsIterator(T, .sequence)
- Kind
- function
- Module
std.mem
pub fn SplitIterator(comptime T: type, comptime delimiter_type: DelimiterType) type
Iterator type for splitting operations, including empty sequences between delimiters.
- Kind
- type function
- Module
std.mem
pub fn first(self: *Self) []const T
Returns a slice of the first field.
- Kind
- function
- Module
std.mem
pub fn next(self: *Self) ?[]const T
Returns a slice of the next field, or null if splitting is complete.
- Kind
- function
- Module
std.mem
pub fn peek(self: *const Self) ?[]const T
Returns a slice of the next field, or null if splitting is complete.
- Kind
- function
- Module
std.mem
pub fn reset(self: *Self) void
Resets the iterator to the initial slice.
- Kind
- function
- Module
std.mem
pub fn rest(self: Self) []const T
Returns a slice of the remaining bytes.
- Kind
- function
- Module
std.mem
pub fn splitScalar(comptime T: type, buffer: []const T, delimiter: T) SplitIterator(T, .scalar)
Returns an iterator that iterates over the slices of `buffer` that are separated by `delimiter`. `splitScalar(u8, "abc|def||ghi", '|')` will return slices for "abc", "def", "", "ghi", null, in that order.
- Kind
- function
- Module
std.mem
pub fn splitSequence(comptime T: type, buffer: []const T, delimiter: []const T) SplitIterator(T, .sequence)
Returns an iterator that iterates over the slices of `buffer` that are separated by the byte sequence in `delimiter`. `splitSequence(u8, "abc||def||||ghi", "||")` will return slices for "abc", "def", "", "ghi", null, in that order.
- Kind
- function
- Module
std.mem
pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool
Returns true if haystack starts with needle.
- Kind
- function
- Module
std.mem
pub fn swap(comptime T: type, noalias a: *T, noalias b: *T) void
Exchanges contents of two memory locations.
- Kind
- function
- Module
std.mem
pub fn toBytes(value: anytype) [@sizeOf(@TypeOf(value))]u8
Given any value, returns a copy of its bytes in an array.
- Kind
- function
- Module
std.mem
pub fn TokenIterator(comptime T: type, comptime delimiter_type: DelimiterType) type
Iterator type for tokenization operations, skipping empty sequences and delimiter sequences.
- Kind
- type function
- Module
std.mem
pub fn next(self: *Self) ?[]const T
Returns a slice of the current token, or null if tokenization is complete, and advances to the next token.
- Kind
- function
- Module
std.mem
pub fn peek(self: *Self) ?[]const T
Returns a slice of the current token, or null if tokenization is complete.
- Kind
- function
- Module
std.mem
pub fn reset(self: *Self) void
Resets the iterator to the initial token.
- Kind
- function
- Module
std.mem
pub fn rest(self: Self) []const T
Returns a slice of the remaining bytes.
- Kind
- function
- Module
std.mem
pub fn tokenizeAny(comptime T: type, buffer: []const T, delimiters: []const T) TokenIterator(T, .any)
Returns an iterator that iterates over the slices of `buffer` that are not any of the items in `delimiters`. `tokenizeAny(u8, " abc|def || ghi ", " |")` will return slices for "abc", "def", "ghi", null, in that order.
- Kind
- function
- Module
std.mem
pub fn tokenizeScalar(comptime T: type, buffer: []const T, delimiter: T) TokenIterator(T, .scalar)
Returns an iterator that iterates over the slices of `buffer` that are not `delimiter`. `tokenizeScalar(u8, " abc def ghi ", ' ')` will return slices for "abc", "def", "ghi", null, in that order.
- Kind
- function
- Module
std.mem
pub fn tokenizeSequence(comptime T: type, buffer: []const T, delimiter: []const T) TokenIterator(T, .sequence)
Returns an iterator that iterates over the slices of `buffer` that are not the sequence in `delimiter`. `tokenizeSequence(u8, "<>abc><def<><>ghi", "<>")` will return slices for "abc><def", "ghi", null, in that order.
- Kind
- function
- Module
std.mem
pub fn toNative(comptime T: type, x: T, endianness_of_x: Endian) T
Converts an integer from specified endianness to host endianness.
- Kind
- function
- Module
std.mem
pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []const T
Remove a set of values from the beginning and end of a slice.
- Kind
- function
- Module
std.mem
pub fn trimEnd(comptime T: type, slice: []const T, values_to_strip: []const T) []const T
Remove a set of values from the end of a slice.
- Kind
- function
- Module
std.mem
pub fn trimStart(comptime T: type, slice: []const T, values_to_strip: []const T) []const T
Remove a set of values from the beginning of a slice.
- Kind
- function
- Module
std.mem
pub fn ValidationAllocator(comptime T: type) type
Detects and asserts if the std.mem.Allocator interface is violated by the caller or the allocator.
- Kind
- type function
- Module
std.mem
pub fn alloc(ctx: *anyopaque, n: usize, alignment: mem.Alignment, ret_addr: usize) ?[*]u8
- Kind
- function
- Module
std.mem
pub fn allocator(self: *Self) Allocator
- Kind
- function
- Module
std.mem
pub fn free(ctx: *anyopaque, buf: []u8, alignment: Alignment, ret_addr: usize) void
- Kind
- function
- Module
std.mem
pub fn init(underlying_allocator: T) @This()
- Kind
- function
- Module
std.mem
pub fn remap(ctx: *anyopaque, buf: []u8, alignment: Alignment, new_len: usize, ret_addr: usize) ?[*]u8
- Kind
- function
- Module
std.mem
pub fn reset(self: *Self) void
- Kind
- function
- Module
std.mem
pub fn resize(ctx: *anyopaque, buf: []u8, alignment: Alignment, new_len: usize, ret_addr: usize) bool
- Kind
- function
- Module
std.mem
pub fn validationWrap(allocator: anytype) ValidationAllocator(@TypeOf(allocator))
Wraps an allocator with basic validation checks.
- Kind
- function
- Module
std.mem
pub fn window(comptime T: type, buffer: []const T, size: usize, advance: usize) WindowIterator(T)
Returns an iterator with a sliding window of slices for `buffer`.
- Kind
- function
- Module
std.mem
pub fn WindowIterator(comptime T: type) type
Iterator type returned by the `window` function for sliding window operations.
- Kind
- type function
- Module
std.mem
pub fn next(self: *Self) ?[]const T
Returns a slice of the next window, or null if window is at end.
- Kind
- function
- Module
std.mem
pub fn reset(self: *Self) void
Resets the iterator to the initial window.
- Kind
- function
- Module
std.mem
pub fn writeInt(comptime T: type, buffer: *[@divExact(@typeInfo(T).int.bits, 8)]u8, value: T, endian: Endian) void
Writes an integer to memory, storing it in twos-complement.
- Kind
- function
- Module
std.mem
pub fn writePackedInt(comptime T: type, bytes: []u8, bit_offset: usize, value: T, endian: Endian) void
Stores an integer to packed memory.
- Kind
- function
- Module
std.mem
pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value: anytype, endian: std.builtin.Endian) void
Stores an integer to packed memory with provided bit_offset, bit_count, and signedness.
- Kind
- function
- Module
std.mem
pub fn zeroes(comptime T: type) T
Generally, Zig users are encouraged to explicitly initialize all fields of a struct explicitly rather than using this function.
- Kind
- function
- Module
std.mem
pub fn zeroInit(comptime T: type, init: anytype) T
Initializes all fields of the struct with their default value, or zero values if no default value is present.
- Kind
- function
- Module
std.mem