VersionBuilder

Struct VersionBuilder 

Source
pub struct VersionBuilder { /* private fields */ }
Expand description

Builder for creating Version programmatically.

This builder allows you to construct version strings when building DBC files programmatically. You can either specify a complete version string or build it incrementally using semantic version components.

§Examples

use dbc_rs::VersionBuilder;

// Direct version string
let version = VersionBuilder::new().version("1.0").build()?;

// Semantic versioning
let version2 = VersionBuilder::new()
    .major(1)
    .minor(2)
    .patch(3)
    .build()?;
assert_eq!(version2.as_str(), "1.2.3");

§Feature Requirements

This builder requires the alloc feature to be enabled.

Implementations§

Source§

impl VersionBuilder

Source

pub fn new() -> Self

Creates a new VersionBuilder with no version set.

§Examples
use dbc_rs::VersionBuilder;

let builder = VersionBuilder::new();
// Must set version before building
let version = builder.version("1.0").build()?;
Source

pub fn version(self, version: &str) -> Self

Sets the complete version string.

This method overrides any previously set version components (major, minor, patch).

§Arguments
  • version - The complete version string (e.g., “1.0”, “1.2.3”, “1.0-beta”)
§Examples
use dbc_rs::VersionBuilder;

let version = VersionBuilder::new()
    .version("1.2.3")
    .build()?;
assert_eq!(version.as_str(), "1.2.3");

// Overrides previous components
let version2 = VersionBuilder::new()
    .major(1)
    .minor(2)
    .version("3.0") // Overrides previous
    .build()?;
assert_eq!(version2.as_str(), "3.0");
Source

pub fn major(self, major: u8) -> Self

Sets the major version number.

If minor() or patch() are called after this, they will append to the version string. If version() is called after this, it will override this value.

§Arguments
  • major - The major version number (0-255)
§Examples
use dbc_rs::VersionBuilder;

let version = VersionBuilder::new()
    .major(1)
    .build()?;
assert_eq!(version.as_str(), "1");

// Combine with minor and patch
let version2 = VersionBuilder::new()
    .major(1)
    .minor(2)
    .patch(3)
    .build()?;
assert_eq!(version2.as_str(), "1.2.3");
Source

pub fn minor(self, minor: u8) -> Self

Sets the minor version number.

If a version string already exists (from major() or version()), this appends the minor version. Otherwise, it creates a new version string with just the minor number.

§Arguments
  • minor - The minor version number (0-255)
§Examples
use dbc_rs::VersionBuilder;

// With major
let version = VersionBuilder::new()
    .major(1)
    .minor(2)
    .build()?;
assert_eq!(version.as_str(), "1.2");

// Without major (creates version "2")
let version2 = VersionBuilder::new()
    .minor(2)
    .build()?;
assert_eq!(version2.as_str(), "2");
Source

pub fn patch(self, patch: u8) -> Self

Sets the patch version number.

If a version string already exists (from major(), minor(), or version()), this appends the patch version. Otherwise, it creates a new version string with just the patch number.

§Arguments
  • patch - The patch version number (0-255)
§Examples
use dbc_rs::VersionBuilder;

// Full semantic version
let version = VersionBuilder::new()
    .major(1)
    .minor(2)
    .patch(3)
    .build()?;
assert_eq!(version.as_str(), "1.2.3");

// Without major/minor (creates version "3")
let version2 = VersionBuilder::new()
    .patch(3)
    .build()?;
assert_eq!(version2.as_str(), "3");
Source

pub fn build(self) -> Result<Version<'static>>

Builds the Version from the builder configuration.

This validates that a version has been set and constructs a Version instance with static lifetime.

§Returns

Returns Ok(Version) if successful, or Err(Error::Version) if:

  • No version has been set (empty version)
§Examples
use dbc_rs::VersionBuilder;

// Build with version string
let version = VersionBuilder::new()
    .version("1.0")
    .build()?;
assert_eq!(version.as_str(), "1.0");

// Build with semantic versioning
let version2 = VersionBuilder::new()
    .major(1)
    .minor(2)
    .patch(3)
    .build()?;
assert_eq!(version2.as_str(), "1.2.3");
§Errors
use dbc_rs::VersionBuilder;

// Missing version
let result = VersionBuilder::new().build();
assert!(result.is_err());

// Empty string is allowed
let version = VersionBuilder::new().version("").build()?;
assert_eq!(version.as_str(), "");

Trait Implementations§

Source§

impl Debug for VersionBuilder

Source§

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

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

impl Default for VersionBuilder

Source§

fn default() -> VersionBuilder

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

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

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.