Struct nextver::CalSem

source ·
pub struct CalSem;
Expand description

Scheme for formats that have both calendar and semantic specifiers, such as <YYYY>.<MM>.<PATCH>.

You would have such a format if you want to be able to increase your version multiple times within the period of your smallest calendar specifier, such a second time in the same day.

See the available specifiers for this scheme in the table.

§Rules

  • The first specifier must be a year (YYYY, YY, or 0Y).
  • For adjacent calendar specifiers a and b, b must be relative to a:
    • month specifiers are relative to year ones (e.g., <YYYY>.<MM>)
    • day specifiers are relative to month ones (e.g., <YYYY>.<MM>.<DD>)
    • week specifiers are relative to year ones (and not month ones) (e.g., <YYYY>.<WW>)
  • The format must end with the PATCH semantic specifier.
    • MINOR may optionally come before PATCH if more granularity is desired.
  • As for all schemes, arbitrary literals can be placed in the format string. For example, dots, hyphens, or any other character(s) can be used, such as y<YYYY>m<MM>d<DD>-p<PATCH>.

§Example Formats

  • <YYYY>.<0M>.<0D>.<PATCH>: Full year, zero-padded month, zero-padded day, and patch. Dot-separated.
  • <0Y>.<0M>.<0D>.<PATCH>: Zero-padded year, zero-padded month, zero-padded day, and patch. Dot-separated.
  • <YYYY>.<0W>-<MINOR>.<PATCH>: Full year, zero-padded week, minor, and patch. Dot- and hyphen-separated.

Implementations§

source§

impl CalSem

source

pub fn next_version_string( format_str: &str, version_str: &str, date: Date, level: CalSemLevel ) -> Result<String, CompositeError>

Increments the version string (formatted by the format string) by the given date and semantic specifier, and returns the new version’s string.

This is a convenience method that creates a temporary Format and Version with Scheme::new_version, and increments it with Version::next.

§Example
use nextver::prelude::*;

let date = Date::utc_now(); // assume today is 2024-02-23

let next_str = CalSem::next_version_string(
  "<YYYY>.<0M>.<PATCH>",
  "2024.01.42",
  date,
  CalSemLevel::Patch
).unwrap();

assert_eq!("2024.02.0", next_str);
§Errors

Returns a CompositeError of all error surface area from Self::new_version and Version::next.

Trait Implementations§

source§

impl Debug for CalSem

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for CalSem

source§

fn eq(&self, other: &CalSem) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Scheme for CalSem

source§

fn new_format(format_str: &str) -> Result<Format<'_, Self>, FormatError>

Parse a format string containing specifier and literal tokens into a Format. Read more
source§

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. Read more
source§

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. Read more
source§

impl Eq for CalSem

source§

impl StructuralPartialEq for CalSem

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.