Module regex_automata::util::wire
source Β· Expand description
Types and routines that support the wire format of finite automata.
Currently, this module just exports a few error types and some small helpers for deserializing dense DFAs using correct alignment.
Structs§
- A hack to align a smaller type
B
with a bigger typeT
. - An error that occurs when deserializing an object defined in this crate.
- An error that occurs when serializing an object from this crate.
Enums§
- BE πBig endian writing.
- Deserialize
Error πKind - LE πLittle endian writing.
Traits§
- Endian πA simple trait for writing code generic over endianness.
Functions§
- add πAdd the given numbers, and on overflow, return an error that includes βwhatβ in the error message.
- alloc_
aligned_ πbuffer Allocate a byte buffer of the given size, along with some initial padding such thatbuf[padding..]
has the same alignment asT
, where the alignment ofT
must be at most8
. In particular, callers should treat the first N bytes (second return value) as padding bytes that must not be overwritten. In all cases, the following identity holds: - check_
alignment πChecks that the given slice has an alignment that matchesT
. - check_
slice_ πlen Checks that the given slice has some minimal length. If itβs smaller than the bound given, then a βbuffer too smallβ error is returned withwhat
describing what the buffer represents. - mul πMultiply the given numbers, and on overflow, return an error that includes βwhatβ in the error message.
- padding_
len πReturns the number of additional bytes required to add to the given length in order to make the total length a multiple of 4. The return value is always less than 4. - Reads the endianness check from the beginning of the given slice and confirms that the endianness of the serialized object matches the expected endianness. If the slice is too small or if the endianness check fails, this returns an error.
- read_
label πReads a NUL terminated label starting at the beginning of the given slice. - read_
pattern_ πid Reads a pattern ID from the given slice. If the slice has insufficient length, then this panics. If the deserialized integer exceeds the pattern ID limit for the current target, then this returns an error. - Reads a pattern ID from the given slice. If the slice has insufficient length, then this panics. Otherwise, the deserialized integer is assumed to be a valid pattern ID.
- read_
state_ πid Reads a state ID from the given slice. If the slice has insufficient length, then this panics. If the deserialized integer exceeds the state ID limit for the current target, then this returns an error. - Reads a state ID from the given slice. If the slice has insufficient length, then this panics. Otherwise, the deserialized integer is assumed to be a valid state ID.
- read_
u16 πRead a u16 from the beginning of the given slice in native endian format. If the slice has fewer than 2 bytes, then this panics. - read_
u32 πRead a u32 from the beginning of the given slice in native endian format. If the slice has fewer than 4 bytes, then this panics. - read_
u128 πRead a u128 from the beginning of the given slice in native endian format. If the slice has fewer than 16 bytes, then this panics. - read_
version πReads a version number from the beginning of the given slice and confirms that is matches the expected version number given. If the slice is too small or if the version numbers arenβt equivalent, this returns an error. - shl πShift
a
left byb
, and on overflow, return an error that includes βwhatβ in the error message. - skip_
initial_ πpadding Reads a possibly empty amount of padding, up to 7 bytes, from the beginning of the given slice. All padding bytes must be NUL bytes. - try_
read_ πstate_ id Attempts to read a state ID from the given slice. If the slice has an insufficient number of bytes or if the state ID exceeds the limit for the current target, then this returns an error. - try_
read_ πu16 Try to read a u16 from the beginning of the given slice in native endian format. If the slice has fewer than 2 bytes, then this returns an error. The error message will include thewhat
description of what is being deserialized, for better error messages.what
should be a noun in singular form. - try_
read_ πu32 Try to read a u32 from the beginning of the given slice in native endian format. If the slice has fewer than 4 bytes, then this returns an error. The error message will include thewhat
description of what is being deserialized, for better error messages.what
should be a noun in singular form. - Try to read a u16 as a usize from the beginning of the given slice in native endian format. If the slice has fewer than 2 bytes or if the deserialized number cannot be represented by usize, then this returns an error. The error message will include the
what
description of what is being deserialized, for better error messages.what
should be a noun in singular form. - Try to read a u32 as a usize from the beginning of the given slice in native endian format. If the slice has fewer than 4 bytes or if the deserialized number cannot be represented by usize, then this returns an error. The error message will include the
what
description of what is being deserialized, for better error messages.what
should be a noun in singular form. - try_
read_ πu128 Try to read a u128 from the beginning of the given slice in native endian format. If the slice has fewer than 16 bytes, then this returns an error. The error message will include thewhat
description of what is being deserialized, for better error messages.what
should be a noun in singular form. - u32s_
to_ πpattern_ ids Safely converts a&[u32]
to&[PatternID]
with zero cost. - u32s_
to_ πstate_ ids Safely converts a&[u32]
to&[StateID]
with zero cost. - Safely converts a
&mut [u32]
to&mut [StateID]
with zero cost. - Writes 0xFEFF as an integer using the given endianness.
- Returns the number of bytes written by the endianness check.
- write_
label πWrites the given label to the buffer as a NUL terminated string. The label given must not contain NUL, otherwise this will panic. Similarly, the label must not be longer than 255 bytes, otherwise this will panic. - write_
label_ πlen Returns the total number of bytes (including padding) that would be written for the given label. This panics if the given label contains a NUL byte or is longer than 255 bytes. (The size restriction exists so that searching for a label during deserialization can be done in small bounded space.) - write_
pattern_ πid Write the given pattern ID to the beginning of the given slice of bytes using the specified endianness. The given slice must have length at leastPatternID::SIZE
, or else this panics. Upon success, the total number of bytes written is returned. - write_
state_ πid Write the given state ID to the beginning of the given slice of bytes using the specified endianness. The given slice must have length at leastStateID::SIZE
, or else this panics. Upon success, the total number of bytes written is returned. - write_
version πWrites the given version number to the beginning of the given slice. - write_
version_ πlen Returns the number of bytes written by writing the version number.
Type Aliases§
- NE π