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
impl UPC
Sourcepub fn check_upc(&self) -> Result<bool, UPCError>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)