Struct parse_changelog::Parser

source ·
pub struct Parser { /* private fields */ }
Expand description

A changelog parser.

Implementations§

source§

impl Parser

source

pub fn new() -> Self

Creates a new changelog parser.

source

pub fn version_format(&mut self, format: &str) -> Result<&mut Self, Error>

Sets the version format.

### v0.1.0 -- 2020-01-01
    ^^^^^

Tip: To customize the text before the version number (e.g., “v” in “# v0.1.0”, “Version “ in “# Version 0.1.0”, etc.), use the prefix_format method instead of this method.

Default

The default version format is based on Semantic Versioning.

This is parsed by using the following regular expression:

^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z\.-]+)?(\+[0-9A-Za-z\.-]+)?$|^Unreleased$

Note: To get the ‘Unreleased’ section in the CLI, you need to explicitly specify ‘Unreleased’ as the version.

Errors

Returns an error if any of the following:

  • The specified format is not a valid regular expression or supported by regex crate.
  • The specified format is empty or contains only whitespace.
source

pub fn prefix_format(&mut self, format: &str) -> Result<&mut Self, Error>

Sets the prefix format.

“Prefix” means the range from the first non-whitespace character after heading to the character before the version (including whitespace characters). For example:

### Version 0.1.0 -- 2020-01-01
   ^^^^^^^^
### v0.1.0 -- 2020-01-01
   ^
Default

By default only “v”, “Version “, “Release “, and “” (no prefix) are allowed as prefixes.

This is parsed by using the following regular expression:

^(v|Version |Release )?
Errors

Returns an error if any of the following:

  • The specified format is not a valid regular expression or supported by regex crate.
source

pub fn parse<'a>(&self, text: &'a str) -> Result<Changelog<'a>, Error>

Parses release notes from the given text.

See crate level documentation for changelog and version format supported by default.

Errors

Returns an error if any of the following:

  • There are multiple release notes for one version.
  • No release was found. This usually means that the changelog isn’t written in the supported format, or that the specified format is wrong if you specify your own format.
source

pub fn parse_iter<'a, 'r>(&'r self, text: &'a str) -> ParseIter<'a, 'r>

Returns an iterator over all release notes in the given text.

Unlike parse method, the returned iterator doesn’t error on duplicate release notes or empty changelog.

See crate level documentation for changelog and version format supported by default.

Trait Implementations§

source§

impl Debug for Parser

source§

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

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

impl Default for Parser

source§

fn default() -> Parser

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.