Module std::text::semver

Semantic versioning โ€” pure Hew implementation.

Parse, inspect, compare, and match semantic version strings according to the SemVer 2.0.0 specification.

Examples

import std::text::semver;

fn main() {
    let v = semver.parse("1.2.3-beta.1");
    println(v.major());
    if v.matches(">=1.0.0") {
        println("compatible");
    }
}

Contents

Functions

Function try_parse

pub fn try_parse(s: string) -> Result<Version, string>

Parse a semantic version string.

Returns Err(string) if the string is not a valid semantic version.

Function parse

pub fn parse(s: string) -> Version

Parse a semantic version string.

Panics if the string is not a valid semantic version. Use try_parse for a structured Result<Version, string> failure surface.

Traits

Trait VersionMethods

Methods available on a parsed Version.

Methods

fn major(self: Self) -> i64

Return the major version number.

fn minor(self: Self) -> i64

Return the minor version number.

fn patch(self: Self) -> i64

Return the patch version number.

fn pre(self: Self) -> string

Return the pre-release label, or an empty string if none.

fn compare(self: Self, other: Version) -> i64

Compare this version to another. Returns -1, 0, or 1.

fn matches(self: Self, req: string) -> bool

Test whether this version satisfies a version requirement string.

fn to_string(self: Self) -> string

Return the version as a string.

fn free(self: Self)

No-op for compatibility (struct versions don't need manual freeing).