ssn 0.1.1

U.S. Social Security Number (SSN) parsing and validation
Documentation
  • Coverage
  • 100%
    11 out of 11 items documented1 out of 7 items with examples
  • Size
  • Source code size: 19.11 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.12 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 30s Average build duration of successful builds.
  • all releases: 31s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • gideonsolutions/tin
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • iajoiner

ssn

U.S. Social Security Number (SSN) parsing and validation for Rust.

Crates.io Documentation CI

Usage

use ssn::Ssn;

// Parse from string with dashes
let ssn: Ssn = "123-45-6789".parse().unwrap();
assert_eq!(ssn.to_string(), "123-45-6789");

// Parse from string without dashes
let ssn: Ssn = "123456789".parse().unwrap();
assert_eq!(ssn.to_string(), "123-45-6789");

// Access components
assert_eq!(ssn.area(), 123);
assert_eq!(ssn.group(), 45);
assert_eq!(ssn.serial(), 6789);

// Create from components
let ssn = Ssn::new(123, 45, 6789).unwrap();

Validation

Validates per SSA rules:

  • Area number (first 3 digits) cannot be 000, 666, or 900-999
  • Group number (middle 2 digits) cannot be 00
  • Serial number (last 4 digits) cannot be 0000
use ssn::{Ssn, SsnParseError};

// Invalid area
assert!(matches!(
    "000-12-3456".parse::<Ssn>(),
    Err(SsnParseError::InvalidArea(0))
));

// Invalid format
assert!(matches!(
    "123+45-6789".parse::<Ssn>(),
    Err(SsnParseError::InvalidFormat)
));

Privacy

The Debug implementation masks sensitive digits:

let ssn: Ssn = "123-45-6789".parse().unwrap();
assert_eq!(format!("{:?}", ssn), "Ssn(XXX-XX-6789)");

License

Apache-2.0