Module version_number::parsers

source ·
Expand description

This crate contains multiple parsers.

In general, it’s easiest to use the well tested parsers::original::Parser, which is also used (currently) by Version::parse. This module contains multiple parsers. In the next paragraphs, each parser is described.

§Parsers

§Original

The original::Parser parses a version, byte by byte (u8). It stores a slice of bytes in the Parser struct and cursor is created at the start of the original::Parser::parse method, which acts as an index pointing to the next token to be parsed.

It can be used to parse two- or three-component major.minor(.patch) versions, where the patch version may or may not be present.

§Modular

The [modular::Parser] has an API which is based on the type state pattern. Internally it uses a Peekable iterator over bytes (u8). The modular parser can parse a version incrementally.

It may be used to parse either a two component major.minor version, or a three component major.minor.patch version, or both.

§Example

In this example we show a basic example of how the original and modular parsers can be used to parse a Version. For more detailed examples, see their respective modules.

// Normally you would only use one of these, not both!
use version_number::parsers::original;
use version_number::parsers::modular;

// As an alternative valid input, we could have used a three component version like `1.64.1`.
let two_component_version = "1.64";

let original_parser = original::Parser::from_slice(two_component_version.as_bytes());
let modular_parser = modular::Parser::from_slice(two_component_version.as_bytes());

let original_parsed = original_parser.parse().unwrap();
let modular_parsed = modular_parser.parse().unwrap();

assert_eq!(original_parsed, modular_parsed );

Re-exports§

Modules§

  • A module for a common error API. Individual parsers may implement their own, more detailed error type. This error type may be used with the convenience parse traits, ParseVersion, ParseBase and ParseFull.
  • The modular parser module.
  • The original parser module.

Traits§