pub trait Scheme: Scheme {
// Provided methods
fn new_format(format_str: &str) -> Result<Format<'_, Self>, FormatError> { ... }
fn new_version<'vs>(
format_str: &str,
version_str: &'vs str,
) -> Result<Version<'vs, Self>, CompositeError> { ... }
fn is_valid(
format_str: &str,
version_str: &str,
) -> Result<bool, FormatError> { ... }
}Expand description
A trait for versioning schemes, which dictate the kinds of specifiers/values allowed in formats/versions and the rules for incrementing them.
Provided Methods§
Sourcefn new_format(format_str: &str) -> Result<Format<'_, Self>, FormatError>
fn new_format(format_str: &str) -> Result<Format<'_, Self>, FormatError>
Parse a format string containing specifier and literal tokens into a Format.
The format string is made up of specifiers and literals. Specifiers indicate numeric values that can change, while literals are fixed text.
See the specifier table here for a list of all specifiers, which
appear as <...> in the format string. To escape a literal <, use <<. > must not be
escaped.
§Example
use nextver::prelude::*;
let format_str = "<YYYY>.<MM>.<PATCH>";
let format = CalSem::new_format(format_str)?;
assert_eq!(format_str, &format.to_string());§Errors
Returns an Err of one of the following FormatError variants:
FormatError::UnterminatedSpecifierif an open bracket is not closed with a closing bracket.FormatError::UnacceptableSpecifierif a specifier is not known to the scheme.FormatError::SpecifiersMustStepDecreaseif specifiers are not in order. See each scheme’s documentation for more details.FormatError::WrongFirstSpecifierif the first specifier is not acceptable for the scheme.FormatError::Incompleteif the last specifier is not acceptable for the scheme.FormatError::NoSpecifiersInFormatif there are no specifiers in the format.
Sourcefn new_version<'vs>(
format_str: &str,
version_str: &'vs str,
) -> Result<Version<'vs, Self>, CompositeError>
fn new_version<'vs>( format_str: &str, version_str: &'vs str, ) -> Result<Version<'vs, Self>, CompositeError>
Parses a version string against a format string, and returns a Version object if the
version string matches the format string. Otherwise, returns a
NextError.
This is a convenience method that creates a temporary Format object with
Scheme::new_format and parses the version string against it with
Format::new_version.
Note: For calendar schemes, the values in version_str are not validated to be actual
dates. For example, 2021.02.31 is valid for the format <YYYY>.<MM>.<DD>, even though
February 31st does not exist.
Returns a result of Version or CompositeError if either of the format or version
operations fail.
§Example
use nextver::prelude::*;
let format_str = "<YYYY>.<0M>.<PATCH>";
let version_str = "2021.02.3";
let version = CalSem::new_version(format_str, version_str)?;
assert_eq!(version_str, &version.to_string());§Errors
Returns a CompositeError of all error surface area from Self::new_format and
Format::new_version.
Sourcefn is_valid(format_str: &str, version_str: &str) -> Result<bool, FormatError>
fn is_valid(format_str: &str, version_str: &str) -> Result<bool, FormatError>
Returns Ok(true) if the given version string is valid for the given format string, or else
Ok(false). Returns an error if the format string could not be parsed.
Returns a result of bool or FormatError if either of the format creation fails.
§Example
use nextver::prelude::*;
assert!(Sem::is_valid("<MAJOR>.<MINOR>.<PATCH>", "1.2.3").unwrap());
assert!(!Sem::is_valid("<MAJOR>.<MINOR>.<PATCH>", "1.2").unwrap());§Errors
Returns a FormatError if the format string could not be parsed.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.