Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for extra::semver #9413

Merged
merged 1 commit into from
Sep 23, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions src/libextra/semver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,25 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! Semver parsing and logic

#[allow(missing_doc)];

//! Semantic version parsing and comparison.
//!
//! Semantic versioning (see http://semver.org/) is a set of rules for
//! assigning version numbers intended to convey meaning about what has
//! changed, and how much. A version number has five parts:
//!
//! * Major number, updated for incompatible API changes
//! * Minor number, updated for backwards-compatible API additions
//! * Patch number, updated for backwards-compatible bugfixes
//! * Pre-release information (optional), preceded by a hyphen (`-`)
//! * Build metadata (optional), preceded by a plus sign (`+`)
//!
//! The three mandatory components are required to be decimal numbers. The
//! pre-release information and build metadata are required to be a
//! period-separated list of identifiers containing only alphanumeric
//! characters and hyphens.
//!
//! An example version number with all five components is
//! `0.8.1-rc.3.0+20130922.linux`.

use std::char;
use std::cmp;
Expand All @@ -20,6 +35,8 @@ use std::io;
use std::option::{Option, Some, None};
use std::to_str::ToStr;

/// An identifier in the pre-release or build metadata. If the identifier can
/// be parsed as a decimal value, it will be represented with `Numeric`.
#[deriving(Clone, Eq)]
pub enum Identifier {
Numeric(uint),
Expand Down Expand Up @@ -49,12 +66,20 @@ impl ToStr for Identifier {
}


/// Represents a version number conforming to the semantic versioning scheme.
#[deriving(Clone, Eq)]
pub struct Version {
/// The major version, to be incremented on incompatible changes.
major: uint,
/// The minor version, to be incremented when functionality is added in a
/// backwards-compatible manner.
minor: uint,
/// The patch version, to be incremented when backwards-compatible bug
/// fixes are made.
patch: uint,
/// The pre-release version identifier, if one exists.
pre: ~[Identifier],
/// The build metadata, ignored when determining version precedence.
build: ~[Identifier],
}

Expand Down Expand Up @@ -202,6 +227,7 @@ fn parse_reader(rdr: @io::Reader) -> Version {
}


/// Parse a string into a semver object.
pub fn parse(s: &str) -> Option<Version> {
if !s.is_ascii() {
return None;
Expand Down