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 type T.
  • An error that occurs when deserializing an object defined in this crate.
  • An error that occurs when serializing an object from this crate.

Enums§

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.
  • Allocate a byte buffer of the given size, along with some initial padding such that buf[padding..] has the same alignment as T, where the alignment of T must be at most 8. 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 matches T.
  • 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 with what 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 by b, and on overflow, return an error that includes β€˜what’ in the error message.
  • 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.
  • 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 the what 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_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 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 the what description of what is being deserialized, for better error messages. what should be a noun in singular form.
  • Safely converts a &[u32] to &[PatternID] with zero cost.
  • 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 least PatternID::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 least StateID::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.
  • Returns the number of bytes written by writing the version number.

Type Aliases§

  • NE πŸ”’