Module infinite_rs::common::extensions

source ·
Expand description

Extensions to BufReader.

Implements read_cstring and read_fixed_string that are not present in the regular BufReader.

  • read_cstring: Given a buffer, reads a character until 0x00 is encountered (null termination), returns the String collected. Errors when given invalid UTF-8.
  • read_fixed_string: Given a buffer and size, reads characters and collects them into a String abd returns it. Ignores unknown UTF-8 encoding, errors out when encountering end-of-file or other IO related errors.
  • read_enumerable: Reads a type that implements the “Readable” trait, which reads the type count times, accumulating the results into a Vec of the type. The type of which to read must be specified as a generic.

These functions are implemented as traits in generics. Requires <Read + Seek> to be satisfied.

Traits§

  • Extension trait for BufReader to add custom reading methods.
  • “Readable” trait that makes sure a “read” method is declared.