bamcensus_core/model/identifier/
fips.rs1use super::{
3 geoid_type::GeoidType, has_geoid_string::HasGeoidString, has_geoid_type::HasGeoidType,
4};
5use serde::{Deserialize, Serialize};
6
7#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
8pub struct State(pub u64);
9
10#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
11pub struct County(pub u64);
12
13#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
14pub struct CountySubdivision(pub u64);
15
16#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
17pub struct Place(pub u64);
18
19#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
20pub struct CensusTract(pub u64);
21
22#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
23pub struct BlockGroup(pub u64);
24
25#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
26pub struct Block(pub String);
27
28#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
29pub struct CongressionalDistrict(pub u64);
30
31#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
32pub struct StateLegislativeDistrictUpperChamber(pub u64);
33
34#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
35pub struct StateLegislativeDistrictLowerChamber(pub u64);
36
37#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)]
38pub struct ZipCodeTabulationArea(pub u64);
39
40impl HasGeoidType for State {
41 fn geoid_type(&self) -> GeoidType {
42 GeoidType::State
43 }
44}
45
46impl HasGeoidType for County {
47 fn geoid_type(&self) -> GeoidType {
48 GeoidType::County
49 }
50}
51impl HasGeoidType for CountySubdivision {
52 fn geoid_type(&self) -> GeoidType {
53 GeoidType::CountySubdivision
54 }
55}
56impl HasGeoidType for Place {
57 fn geoid_type(&self) -> GeoidType {
58 GeoidType::Place
59 }
60}
61impl HasGeoidType for CensusTract {
62 fn geoid_type(&self) -> GeoidType {
63 GeoidType::CensusTract
64 }
65}
66impl HasGeoidType for BlockGroup {
67 fn geoid_type(&self) -> GeoidType {
68 GeoidType::BlockGroup
69 }
70}
71impl HasGeoidType for Block {
72 fn geoid_type(&self) -> GeoidType {
73 GeoidType::Block
74 }
75}
76
77impl HasGeoidString for State {
78 fn geoid_string(&self) -> String {
79 format!("{:02}", self.0)
80 }
81}
82
83impl HasGeoidString for County {
84 fn geoid_string(&self) -> String {
85 format!("{:03}", self.0)
86 }
87}
88impl HasGeoidString for CountySubdivision {
89 fn geoid_string(&self) -> String {
90 format!("{:05}", self.0)
91 }
92}
93impl HasGeoidString for Place {
94 fn geoid_string(&self) -> String {
95 format!("{:05}", self.0)
96 }
97}
98impl HasGeoidString for CensusTract {
99 fn geoid_string(&self) -> String {
100 format!("{:06}", self.0)
101 }
102}
103impl HasGeoidString for BlockGroup {
104 fn geoid_string(&self) -> String {
105 self.0.to_string()
106 }
107}
108impl HasGeoidString for Block {
109 fn geoid_string(&self) -> String {
110 self.0.clone()
111 }
112}
113impl HasGeoidString for CongressionalDistrict {
114 fn geoid_string(&self) -> String {
115 format!("{:02}", self.0)
116 }
117}
118impl HasGeoidString for StateLegislativeDistrictUpperChamber {
119 fn geoid_string(&self) -> String {
120 format!("{:03}", self.0)
121 }
122}
123impl HasGeoidString for StateLegislativeDistrictLowerChamber {
124 fn geoid_string(&self) -> String {
125 format!("{:03}", self.0)
126 }
127}
128impl HasGeoidString for ZipCodeTabulationArea {
129 fn geoid_string(&self) -> String {
130 format!("{:05}", self.0)
131 }
132}