Cal

Struct Cal 

Source
pub struct Cal;
Expand description

Scheme for formats that have only calendar specifiers, such as <YYYY>.<MM>.<DD>.

This scheme is less useful than CalSem because there is no way to increment it twice in the same period of its least significant specifier. For example, a version with format <YYYY>.<MM>.<DD> can only be incremented/updated once per 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 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>)
  • 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>.

§Example Formats

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

Implementations§

Source§

impl Cal

Source

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

Increments the version string (formatted by the format string) by the given date 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 = Cal::next_version_string(
  "<YYYY>.<0M>.<0D>",
  "2001.02.03",
  date
).unwrap();

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

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

Trait Implementations§

Source§

impl Debug for Cal

Source§

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

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

impl PartialEq for Cal

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Scheme for Cal

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 Cal

Source§

impl StructuralPartialEq for Cal

Auto Trait Implementations§

§

impl Freeze for Cal

§

impl RefUnwindSafe for Cal

§

impl Send for Cal

§

impl Sync for Cal

§

impl Unpin for Cal

§

impl UnwindSafe for Cal

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>,

Source§

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>,

Source§

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.