Giter Site home page Giter Site logo

rust-gtin-validate's Introduction

Rust GTIN Validator

Build Status Coverage Status Documentation

Validate and correct GTIN codes, such as UPC-A and EAN-13, in Rust.

Features

Currently supported types:

  • GTIN-8
  • GTIN-12 (UPC-A)
  • GTIN-13 (EAN-13)
  • GTIN-14

Validation features include:

  • Check that the string contains the correct number of digits
  • Compute the check-digit and confirm that it matches

Correction features include:

  • Add zero-padding (some software treats these codes as integers)
  • Strip whitespace from both sides of the code

How to use

For full details, check the documentation.

Briefly, here are the function declarations:

// return true if the code is valid, false otherwise
fn gtin8::check(code: &str) -> bool;
fn gtin12::check(code: &str) -> bool;
fn gtin13::check(code: &str) -> bool;
fn gtin14::check(code: &str) -> bool;

// return a corrected String or Err
fn gtin8::fix(code: &str) -> Result<String, FixError>;
fn gtin12::fix(code: &str) -> Result<String, FixError>;
fn gtin13::fix(code: &str) -> Result<String, FixError>;
fn gtin14::fix(code: &str) -> Result<String, FixError>;

For example, you can validate UPC-A codes:

use gtin_validate::gtin12;

assert_eq!(gtin12::check("000000000000"), true);
assert_eq!(gtin12::check("000000000001"), false);

You can add this line to your Cargo.toml file:

[dependencies]
gtin-validate = "1.3.0"

Contributing

Found a bug? Report an issue through GitHub.

Want to hack on the code? Submit a pull request.

rust-gtin-validate's People

Contributors

austinhartzheim avatar ayakovlenko avatar gknirps avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

gknirps

rust-gtin-validate's Issues

FixError types should implement some more basic traits

Hi,
for some of my use cases, it would be nice if the FixError-types (such as gtin14::FixError) implemented some more of the basic traits. I would suggest Clone, PartialEq, Eq, Hash and maybe Copy. Right now, they only implement Debug.

Are there any reasons against this?

Perform actual speed comparison for work on the `optimize` branch

We haven't actually run side-by-side speed comparisons of the master and optimize branches. We need to confirm that our optimizations are real and that the criterion crate isn't misleading us.

Done when:

  • Comparison is completed.
  • Decide whether to merge any of the changes based on results.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.