[][src]Crate lenient_semver

Lenient parser for Semantic Version numbers.

Motivation

This crate aims to provide an alternative parser for semver Versions.

Instead of adhering to the semver specification, this parser is more lenient in what it allows. The differenc include:

  • Minor and Path are optional an default to 0 (e.g. "1" parses at "1.0.0")
  • Pre-release identifier may be separated by . as well (e.g. "1.2.3.rc1" parses at "1.2.3-rc1")
  • Some pre-release identifiers are parsed as build identifier (e.g. "1.2.3.Final" parses at "1.2.3+Final")

This diagram shows lenient parsing grammar

have a look at doc/railroad.svg

Examples

use semver::Version;

let version = lenient_semver::parse("1.2.3");
assert_eq!(version, Ok(Version::new(1, 2, 3)));

// examples of a version that would not be accepted by semver_parser
assert_eq!(
    lenient_semver::parse("1.2.M1").unwrap(),
    Version::parse("1.2.0-M1").unwrap()
);
assert!(Version::parse("1.2.M1").is_err());

assert_eq!(
    lenient_semver::parse("1").unwrap(),
    Version::parse("1.0.0").unwrap()
);
assert!(Version::parse("1").is_err());

assert_eq!(
    lenient_semver::parse("1.2.3.Final").unwrap(),
    Version::parse("1.2.3+Final").unwrap()
);
assert!(Version::parse("1.2.3.Final").is_err());

Structs

Error

Possible errors that happen during parsing and the location of the token where the error occurred.

OwnedError

Owned version of Error which clones the input string.

Enums

ErrorKind

Possible errors that can happen. These don't include an information as those are covered by various error methods like Error::erroneous_input.

Functions

parse

Parse a string slice into a Version. This parser does not require semver-specification conformant input and is more lenient in what it allows. The differenc include: