[][src]Struct upc_checker::UPC

pub struct UPC {
    pub upc: UPCStandard,
    pub check_digit: i8,
}

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: UPCStandardcheck_digit: i8

Methods

impl UPC[src]

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

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

impl Debug for UPC[src]

impl PartialEq<UPC> for UPC[src]

impl Clone for UPC[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl Unpin for UPC

impl Sync for UPC

impl Send for UPC

Blanket Implementations

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]