| Crates.io | ixa-fips |
| lib.rs | ixa-fips |
| version | 0.1.4 |
| created_at | 2025-06-03 14:42:44.251549+00 |
| updated_at | 2025-12-09 15:01:12.216787+00 |
| description | A library for efficiently working with FIPS region codes |
| homepage | https://github.com/CDCgov/ixa |
| repository | https://github.com/CDCgov/ixa |
| max_upload_size | |
| id | 1699135 |
| size | 56,083 |
Represent, parse, and manipulate hierarchical FIPS region codes in just 64 bits.
Federal Information Processing Series (FIPS)
is a standardized set of geographic codes useful for identifying places and
regions like counties and voting districts. This library provides an efficient
representation of a subset of these codes, in particular hierarchical region
codes suitable for identifying schools, workplaces, and homes. The primary data
type FIPSCode has explicit fields for state, county, and census tract, and has
additional fields convenient for user-defined specificity and even additional
arbitrary data.
u64,
minimizing memory use and hash-map overhead.FIPSCode values
without intermediate heap allocations.This crate is designed to be usable with any revision of the standard. The standard-dependent properties of this library are:
USState enum the use of which
is optional.| Type / Module | Purpose |
|---|---|
FIPSCode |
64-bit value encoding state + county + tract + category + id (10 spare bits for you) |
parser |
Zero-allocation conversions &str ⇆ FIPSCode / fragments |
USState |
Exhaustive enum of valid state codes* (fits in the 6 bits allocated by FIPSCode) |
FIPSError |
Represents value out of range errors. |
* This is a minimal subset of FIPS state and state equivalent codes which have been stable for every FIPS standard revision so far. See the 2020 FIPS Standard here.
use ixa_fips::{FIPSCode, USState};
let code = FIPSCode::with_tract(
USState::TX,
201, // county
1234, // census tract
);
// Pattern-match the components later:
assert_eq!(code.state(), USState::TX);
Example parsing a complete FIPS code (state + county + tract):
// Example: "01001020100" = Alabama (01), Autauga County (001), Tract 020100
let input = "01001020100";
// First parse the state
let (rest, state) = parse_state_code(input).unwrap();
assert_eq!(rest, "001020100");
// Then parse the county
let (rest, county) = parse_county_code(rest).unwrap();
assert_eq!(rest, "020100");
// Finally parse the tract
let (rest, tract) = parse_tract_code(rest).unwrap();
assert_eq!(rest, "");
// Verify the parsed values (assuming USState enum implementation)
assert_eq!(state, USState::AL);
assert_eq!(county, 1);
assert_eq!(tract, 20100);