1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! # FIPS Geographic Region Code Library
//!
//! FIPS geographic region codes are used to represent hierarchical geographic regions from the state level down to the
//! "block" level. They are augmented in some synthetic population datasets with additional ID numbers for households,
//! workplaces, and schools. This library provides types to represent FIPS geographic region codes (and "code fragments"),
//! efficient representations, and utilities to convert to and from textual representations ([`crate::parser`]).
//!
//! The [`crate::aspr`] module provides types for representing records from the ASPR synthetic population dataset, and the
//! [`crate::aspr::parser`] submodule provides parsers for textual representations of ASPR records.
//!
//! The `aspr_archive` feature (enabled by default) enables the [`crate::aspr::archive`] module, which provides a reader
//! for ASPR synthetic population data files, including files that are within a zip archive.
pub use FIPSError;
pub use ;
pub use USState;
// Convenience constants
const FOUR_BIT_MASK: u8 = 15; // 2^4-1
const SEVEN_BIT_MASK: u8 = 127; // 2^7-1
const NINE_BIT_MASK: u16 = 511; // 2^9-1
const TEN_BIT_MASK: u16 = 1023; // 2^10-1
const FOURTEEN_BIT_MASK: u16 = 16_383; // 2^14-1
const TWENTY_BIT_MASK: u32 = 1_048_575; // 2^20-1
// Offsets of the bit fields in the encoded FIPS code
const STATE_OFFSET: usize = 57;
const COUNTY_OFFSET: usize = 47;
const TRACT_OFFSET: usize = 27;
const CATEGORY_OFFSET: usize = 23;
const ID_OFFSET: usize = 9;
// const DATA_OFFSET: usize = 0;
// Numeric types used for code fragments. By convention, zero values are reserved for "no data."
/// The numeric type used for the state code fragment; `u8`
pub type StateCode = u8;
/// The numeric type used for the county code fragment; `u16`
pub type CountyCode = u16;
/// The numeric type used for the tract code fragment; `u32`
pub type TractCode = u32;
/// The numeric type used for the setting category code fragment; `u8`
pub type SettingCategoryCode = u8;
/// The numeric type used for the id code fragment; `u16`
pub type IdCode = u16;
/// The numeric type used for the data code fragment; `u16`
pub type DataCode = u16;