Fix failing doc test, adjust README

This commit is contained in:
Nathan Fisher 2024-01-31 22:59:31 -05:00
parent 98b74bd2a7
commit 17e52c2b01
2 changed files with 27 additions and 17 deletions

View File

@ -56,19 +56,6 @@ fn main() -> Result<(), VersionError> {
Ok(()) Ok(())
} }
``` ```
### Git
Git revisions may be used, but may only be compared with other Git revisions. Git
revisions are ordered by date/time and formatted as Unix timestamps.
```
use version::{prelude::VersionError, Version};
fn main() -> Result<(), VersionError> {
let va: Version = "git_r2d2xxx.1705881508-i486".parse()?;
let vb: Version = "git_c3p0xxx.1705881612-i486".parse()?;
assert!(va < vb);
Ok(())
}
```
## Internals ## Internals
When comparing version numbers for equality or ordering, the semver-like versions When comparing version numbers for equality or ordering, the semver-like versions
@ -79,11 +66,12 @@ the prerelease number. The next four bits are used as bitflags representing the
type of prerelease, which may be `PreRelease::None` (which gets the highest bit in type of prerelease, which may be `PreRelease::None` (which gets the highest bit in
the set). the set).
| bits | 15 | 14 | 13 | 12 | 0-11 | | bits | 15 | 14 | 13 | 12 | 11 | 0-10 |
| ---- | --- | --- | --- | --- | ---- | | ---- | --- | --- | --- | --- | --- | ---- |
| use | PreRelease::None | PreRelease::Rc | PreRelease::Beta | PreRelease::Alpha | Numerical component | | use | PreRelease::None | PreRelease::Rc | PreRelease::Beta | PreRelease::Alpha | PreRelease::Git | Numerical component |
This gives an upper limit of 2^12 or 4096 for the numerical component, which is more This gives an upper limit of 2^11 or 2048 for the numerical component of the prerelease,
and 2^12 or 4096 for each SemVer field, which is more
than adequate. By placing the flags in this way, alpha releases will always be lower than adequate. By placing the flags in this way, alpha releases will always be lower
than beta, which will be lower than release candidates, which will be lower than no than beta, which will be lower than release candidates, which will be lower than no
pre-release versions. pre-release versions.

View File

@ -10,7 +10,15 @@ pub enum Arch {
Any, Any,
Arm, Arm,
Arm64, Arm64,
Loongson,
Mips32,
Mips64,
PowerPC,
PowerPC64,
RiscV64, RiscV64,
S390x,
Sparc,
Sparc64,
X86, X86,
X86_64, X86_64,
} }
@ -24,7 +32,15 @@ impl fmt::Display for Arch {
Self::Any => "any", Self::Any => "any",
Self::Arm => "armv7l", Self::Arm => "armv7l",
Self::Arm64 => "aarch64", Self::Arm64 => "aarch64",
Self::Loongson => "loongson",
Self::Mips32 => "mips32",
Self::Mips64 => "mips64",
Self::PowerPC => "ppc",
Self::PowerPC64 => "ppc64",
Self::RiscV64 => "riscv64", Self::RiscV64 => "riscv64",
Self::S390x => "s390x",
Self::Sparc => "sparc",
Self::Sparc64 => "sparc64",
Self::X86 => "i486", Self::X86 => "i486",
Self::X86_64 => "x86_64", Self::X86_64 => "x86_64",
} }
@ -40,7 +56,13 @@ impl str::FromStr for Arch {
"any" | "Any" | "noarch" => Ok(Self::Any), "any" | "Any" | "noarch" => Ok(Self::Any),
"armv7l" | "ArmV7L" | "Armv7L" => Ok(Self::Arm), "armv7l" | "ArmV7L" | "Armv7L" => Ok(Self::Arm),
"arm64" | "Arm64" | "aarch64" | "Aarch64" => Ok(Self::Arm64), "arm64" | "Arm64" | "aarch64" | "Aarch64" => Ok(Self::Arm64),
"Loongson" | "loongson" => Ok(Self::Loongson),
"Mips" | "mips" | "Mips32" | "mips32" => Ok(Self::Mips32),
"Mips64" | "mips64" => Ok(Self::Mips64),
"PowerPC" | "powerpc" | "PPC" | "ppc" => Ok(Self::PowerPC),
"PowerPC64" | "powerpc64" | "PPC64" | "ppc64" => Ok(Self::PowerPC64),
"RiscV64" | "riscv64" => Ok(Self::RiscV64), "RiscV64" | "riscv64" => Ok(Self::RiscV64),
"S390x" | "s390x" => Ok(Self::S390x),
"x86" | "X86" | "i486" => Ok(Self::X86), "x86" | "X86" | "i486" => Ok(Self::X86),
"X86_64" | "Amd64" | "x86_64" | "amd64" => Ok(Self::X86_64), "X86_64" | "Amd64" | "x86_64" | "amd64" => Ok(Self::X86_64),
_ => Err(Error::ParseArch), _ => Err(Error::ParseArch),