Struct Version

Source
pub struct Version { /* private fields */ }

Implementations§

Source§

impl Version

Source

pub fn new(vector: Vec<u64>) -> Self

Create new instance from vector

§Example
use version_operators::Version;

let vector = vec![1, 14, 3];

let version = Version::new(vector.clone());

assert_eq!(version.to_vector(), vector);
Source

pub fn from_split_callback<F>(input: &str, callback: F) -> Self
where F: Fn(char) -> bool,

Create new instance using a custom spliter callback function or closure

§Example with Closure
use version_operators::Version;

let version = Version::from_split_callback("1.14.3", |c: char| !c.is_numeric());

assert_eq!(version.to_vector(), vec![1, 14, 3]);
§Example with Function
use version_operators::Version;

fn custom_spliter(c: char) -> bool {
    !c.is_numeric()
}

let version = Version::from_split_callback("1.14.3", &custom_spliter);

assert_eq!(version.to_vector(), vec![1, 14, 3]);
Source

pub fn from_str(input: &str) -> Self

Convert &str to vector of unsigned-integers

§Example
use version_operators::Version;

let version = Version::from_str("1.14.3");

assert_eq!(version.to_vector(), vec![1, 14, 3]);
Examples found in repository?
examples/version-math.rs (line 26)
15fn main() {
16    let mut iter = env::args().skip(1);
17    let mut version_args: Vec<String> = vec![];
18    loop {
19        if version_args.len() < 3 {
20            let arg = iter.next();
21            match arg {
22                Some(value) => version_args.push(value),
23                _ => break,
24            }
25        } else {
26            let left = Version::from_str(&version_args[0]);
27            let operator: &str = &version_args[1].to_owned();
28            let right = Version::from_str(&version_args[2]);
29            let result = match operator {
30                "+" | "-add" => left + right,
31                "-" | "-sub" => left - right,
32                _ => panic!("Unrecognized operator! Try '+'/'-add' or '-'/'-sub'"),
33            };
34            println!("{:?}", result.to_vector());
35            version_args = vec![];
36        }
37    }
38}
More examples
Hide additional examples
examples/version-increment.rs (line 18)
7fn main() {
8    let mut iter = env::args().skip(1);
9    let mut version_args: Vec<String> = vec![];
10    loop {
11        if version_args.len() < 2 {
12            let arg = iter.next();
13            match arg {
14                Some(value) => version_args.push(value),
15                _ => break,
16            }
17        } else {
18            let mut version = Version::from_str(&version_args[0]);
19            let position: &u8 = &version_args[1].to_owned()
20                                                .parse::<u8>()
21                                                .unwrap();
22
23            let mut vector: Vec<u64> = vec![];
24            for _ in 0..position.to_owned() {
25                vector.push(0);
26            }
27            vector.push(1);
28            println!("{:?}", vector);
29
30            version += Version::from_vec(vector);
31            println!("{:?}", version.to_vector());
32
33            version_args = vec![];
34        }
35    }
36}
examples/version-compare.rs (line 26)
15fn main() {
16    let mut iter = env::args().skip(1);
17    let mut version_args: Vec<String> = vec![];
18    loop {
19        if version_args.len() < 3 {
20            let arg = iter.next();
21            match arg {
22                Some(value) => version_args.push(value),
23                _ => break,
24            }
25        } else {
26            let left = Version::from_str(&version_args[0]);
27            let comparator: &str = &version_args[1].to_owned();
28            let right = Version::from_str(&version_args[2]);
29            let result = match comparator {
30                "==" | "-eq" => left == right,
31                "!=" | "-ne" => left != right,
32                ">=" | "-ge" => left >= right,
33                ">" | "-gt" => left > right,
34                "<=" | "-le" => left <= right,
35                "<" | "-lt" => left < right,
36                _ => panic!("Unrecognized operator! Try '==' or '!=' or '-lt' or '-gt'"),
37            };
38            println!("{:?}", result);
39            version_args = vec![];
40        }
41    }
42}
Source

pub fn from_vec(vector: Vec<u64>) -> Self

Save vector of unsigned-integers to new instance of Version

§Example
use version_operators::Version;

let vector = vec![1, 14, 3];
let version = Version::from_vec(vector.clone());

assert_eq!(version.to_vector(), vector);
Examples found in repository?
examples/version-increment.rs (line 30)
7fn main() {
8    let mut iter = env::args().skip(1);
9    let mut version_args: Vec<String> = vec![];
10    loop {
11        if version_args.len() < 2 {
12            let arg = iter.next();
13            match arg {
14                Some(value) => version_args.push(value),
15                _ => break,
16            }
17        } else {
18            let mut version = Version::from_str(&version_args[0]);
19            let position: &u8 = &version_args[1].to_owned()
20                                                .parse::<u8>()
21                                                .unwrap();
22
23            let mut vector: Vec<u64> = vec![];
24            for _ in 0..position.to_owned() {
25                vector.push(0);
26            }
27            vector.push(1);
28            println!("{:?}", vector);
29
30            version += Version::from_vec(vector);
31            println!("{:?}", version.to_vector());
32
33            version_args = vec![];
34        }
35    }
36}
Source

pub fn to_vector(self) -> Vec<u64>

Passes ownership of vector within Version instance

§Example
use version_operators::Version;

let version = Version::from_str("1.14.3");

assert_eq!(version.to_vector(), vec![1, 14, 3]);
Examples found in repository?
examples/version-math.rs (line 34)
15fn main() {
16    let mut iter = env::args().skip(1);
17    let mut version_args: Vec<String> = vec![];
18    loop {
19        if version_args.len() < 3 {
20            let arg = iter.next();
21            match arg {
22                Some(value) => version_args.push(value),
23                _ => break,
24            }
25        } else {
26            let left = Version::from_str(&version_args[0]);
27            let operator: &str = &version_args[1].to_owned();
28            let right = Version::from_str(&version_args[2]);
29            let result = match operator {
30                "+" | "-add" => left + right,
31                "-" | "-sub" => left - right,
32                _ => panic!("Unrecognized operator! Try '+'/'-add' or '-'/'-sub'"),
33            };
34            println!("{:?}", result.to_vector());
35            version_args = vec![];
36        }
37    }
38}
More examples
Hide additional examples
examples/version-increment.rs (line 31)
7fn main() {
8    let mut iter = env::args().skip(1);
9    let mut version_args: Vec<String> = vec![];
10    loop {
11        if version_args.len() < 2 {
12            let arg = iter.next();
13            match arg {
14                Some(value) => version_args.push(value),
15                _ => break,
16            }
17        } else {
18            let mut version = Version::from_str(&version_args[0]);
19            let position: &u8 = &version_args[1].to_owned()
20                                                .parse::<u8>()
21                                                .unwrap();
22
23            let mut vector: Vec<u64> = vec![];
24            for _ in 0..position.to_owned() {
25                vector.push(0);
26            }
27            vector.push(1);
28            println!("{:?}", vector);
29
30            version += Version::from_vec(vector);
31            println!("{:?}", version.to_vector());
32
33            version_args = vec![];
34        }
35    }
36}

Trait Implementations§

Source§

impl Add for Version

Implement addition (+) operator

Source§

fn add(self, other: Self) -> Self

§Example
use version_operators::Version;

let version_one = Version::from_str("1.14.3");
let version_two = Version::from_str("1.14.2");

let version_new = version_one + version_two;

assert!(version_new.to_vector() == vec![2, 28, 5]);
Source§

type Output = Version

The resulting type after applying the + operator.
Source§

impl AddAssign for Version

Implement add assignment (+=) operator

Source§

fn add_assign(&mut self, other: Self)

§Example
use version_operators::Version;

let mut version_one = Version::from_str("1.14.3");
let version_two = Version::from_str("1.14.2");

version_one += version_two;

assert!(version_one.to_vector() == vec![2, 28, 5]);
Source§

impl Clone for Version

Source§

fn clone(&self) -> Version

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Version

Source§

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

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

impl Ord for Version

Implement greater/less-than (<, >) and operators

Source§

fn cmp(&self, other: &Self) -> Ordering

§Example Greater Than
use version_operators::Version;

let version_one = Version::from_str("1.14.3");
let version_two = Version::from_str("1.14.2");

assert!(version_one > version_two);
assert_eq!(version_two > version_one, false);
§Example Less Than
use version_operators::Version;

let version_one = Version::from_str("1.14.3");
let version_two = Version::from_str("1.14");

assert!(version_two < version_one);
assert_eq!(version_one < version_two, false);
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Version

Implement equal/not-equal (==, !=) operators

Source§

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

§Example Equality
use version_operators::Version;

let version_one = Version::from_str("1.14.3");
let version_two = Version::from_str("1.14.3");

assert!(version_one == version_two);
assert_eq!(version_one, version_two);
§Example Inequality
use version_operators::Version;

let version_one = Version::from_str("1.14");
let version_two = Version::from_str("1.14.2");

assert!(version_one != version_two);
assert_ne!(version_one, version_two);
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 PartialOrd for Version

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Sub for Version

Implement subtraction (-) operator

Source§

fn sub(self, other: Self) -> Self

§Example
use version_operators::Version;
 
let version_one = Version::from_str("1.14.3");
let version_two = Version::from_str("1.14.2");

let version_new = version_one - version_two;

assert!(version_new.to_vector() == vec![0, 0, 1]);
Source§

type Output = Version

The resulting type after applying the - operator.
Source§

impl SubAssign for Version

Implement subtract assignment (-=) operator

Source§

fn sub_assign(&mut self, other: Self)

§Example
use version_operators::Version;

let mut version = Version::from_str("1.14.3");

version -= Version::from_str("1.14.2");

assert!(version.to_vector() == vec![0, 0, 1]);
Source§

impl Eq for Version

See: PartialEq implementation

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.