Rut Library 🇨🇱
A Rust library for parsing, format and validate a Chilean ID (RUT)
Usage
This crate is on crates.io and can be used by adding rut-lib to your dependencies in your project's Cargo.toml.
[]
= "0.1.2"
If you're using Rust 2015, then you'll also need to add it to your crate root:
extern crate rut_lib;
Examples
Parsing from String
A easy way to validate and create a Rut using the from method, this returns a Result<Rut, Error>
The input must be a valid String format, a few examples:
17.951.585-717951585-7179515857
use Rut;
let stringifier_rut = "17951585-7";
match from
Output
Error behaviour
use Rut;
let stringifier_rut = "17,951,585-7";
match from
Output
use Rut;
let stringifier_rut = "17951585K";
match from
Output
Parsing from Number
Create a Rut using the from_number method (If you don't have a DV), this returns a Result<Rut, Error>
The input must be a number (u32) and stay in a range from 1_000_000 to 99_999_999
use Rut;
let number = 24136773;
match from_number
Output
Error behaviour
use Rut;
let number = 999_999;
match from_number
Output
Randomize Rut
Generate a randomize rut from scratch for testing use
Example:
use Rut;
let rut = randomize;
println!;
println!;
println!;
Output
Prettify Format
The to_format method receive a Format (enum) as input to returns a Prettify Rut
use ;
let input = "179515857";
let rut = from.unwrap;
println!;
println!;
println!;
Output
License
This project is licensed under the terms of the MIT License.