1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
#![doc(html_root_url = "https://docs.charr.xyz/rust-version/")] #![feature(try_from, catch_expr)] #![cfg_attr(test, deny(warnings, missing_docs, missing_debug_implementations))] #[cfg(feature = "serde")] extern crate serde; #[cfg(feature = "serde")] use serde::{ser, de}; extern crate data_encoding; extern crate either; extern crate itoa; extern crate toml; extern crate reqwest; #[macro_use] extern crate serde_derive; /* use std::error::Error; use std::fmt; use std::io; use std::process::Command; use std::str::FromStr; */ mod beta; mod channel; mod commit; mod date; mod parse; mod release; mod version; pub use beta::*; pub use channel::*; pub use commit::*; pub use date::*; pub use release::*; pub use version::*; /* impl FromStr for Version { type Err = VersionParseError; fn from_str(s: &str) -> Result<Version, VersionParseError> { // make sure that we're non-empty let first = match s.chars().next() { Some(c) => c, None => return Err(VersionParseError(())), }; // depending on first character, we might have a semver match first { // semver: parse that into a stable version '0'...'9' => s.parse::<SemVer>() .map(|v| Version::OldStable(v)) .map_err(|_| VersionParseError(())), // just "stable" 's' => if &s[1..] == "table" { Ok(Version::Stable) } else { Err(VersionParseError(())) }, // just "beta" 'b' => if &s[1..] == "eta" { Ok(Version::Beta) } else { Err(VersionParseError(())) }, // "nightly" or "nightly-date" 'n' => if &s[1..7] == "ightly" { // if there's nothing left, just "nightly" if s.len() == 7 { Ok(Version::Nightly) // otherwise, we've got to have a date after it } else { if Some('-') == s[7..].chars().next() { s[8..].parse::<NaiveDate>() .map(|d| Version::OldNightly(d)) .map_err(|_| VersionParseError(())) // no dash = invalid nightly } else { Err(VersionParseError(())) } } // n-jibberish } else { Err(VersionParseError(())) }, // something completely bogus _ => Err(VersionParseError(())), } } } impl fmt::Display for Version { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { Version::OldStable(ref ver) => fmt::Display::fmt(&ver, f), Version::Stable => f.write_str("stable"), Version::Beta => f.write_str("beta"), Version::OldNightly(ref date) => write!(f, "nightly-{}", date), Version::Nightly => f.write_str("nightly"), } } } impl fmt::Debug for Version { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(self, f) } } impl de::Deserialize for Version { fn deserialize<D: de::Deserializer>(d: D) -> Result<Self, D::Error> { struct Visitor; impl de::Visitor for Visitor { type Value = Version; fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str("a rustc version") } fn visit_str<E: de::Error>(self, value: &str) -> Result<Version, E> { value.parse().map_err(|_| E::invalid_value(de::Unexpected::Str(value), &self)) } } d.deserialize_str(Visitor) } } impl ser::Serialize for Version { fn serialize<S: ser::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> { s.collect_str(self) } } */