upc_checker

Struct UPC

Source
pub struct UPC {
    pub upc: UPCStandard,
    pub check_digit: i8,
}
Expand description

Main UPC structure containing the base UPC code alonside it’s check digit. This is the core of the upc_checker library

§Params

  • upc: A UPCStandard enum
  • check_digit: An i8 int for the UPC code’s check digit

§Examples

NOTE: The below example is a demo and will not work with the given upc code & check digit in practise.

extern crate upc_checker;

let my_code_vector = upc_checker::UPCStandard::UPCA(
    [0,1,2,3,4,5,6,7,8,9,0]
); // NOTE digits should be 0-9.
let my_check_digit: i8 = 2; // NOTE check digit should be 0-9

let my_upc_code = upc_checker::UPC {
    upc: my_code_vector,
    check_digit: my_check_digit,
};

match my_upc_code.check_upc() {
    Ok(x) => println!("Is the code valid?: {}", x),
    Err(upc_checker::UPCError::UPCOverflow) => {
        println!("UPC code overflow! Please use only 0-9!");
    },
    Err(upc_checker::UPCError::CheckDigitOverflow) => {
        println!("UPC check digit overflow! Please use only 0-9!");
    },
};

Fields§

§upc: UPCStandard§check_digit: i8

Implementations§

Source§

impl UPC

Source

pub fn check_upc(&self) -> Result<bool, UPCError>

The main frontend method for the UPC structure. This method uses data from the super UPC struct and returns a Result enum with either a bool (IF the check digit is valid) or an instance of the UPCError enum.

NOTE: For more documentation & examples, please view the UPC documentation directly.

Trait Implementations§

Source§

impl Clone for UPC

Source§

fn clone(&self) -> UPC

Returns a copy 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 UPC

Source§

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

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

impl PartialEq for UPC

Source§

fn eq(&self, other: &UPC) -> 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 StructuralPartialEq for UPC

Auto Trait Implementations§

§

impl Freeze for UPC

§

impl RefUnwindSafe for UPC

§

impl Send for UPC

§

impl Sync for UPC

§

impl Unpin for UPC

§

impl UnwindSafe for UPC

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.