bamcensus-core 0.1.0

A tool for downloading US Census datasets written in Rust
Documentation
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
use crate::model::identifier::{fips::State, has_geoid_string::HasGeoidString, Geoid};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Copy, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum StateCode {
    Alabama,
    Alaska,
    Arizona,
    Arkansas,
    California,
    Colorado,
    Connecticut,
    Delaware,
    DistrictOfColumbia,
    Florida,
    Georgia,
    Hawaii,
    Idaho,
    Illinois,
    Indiana,
    Iowa,
    Kansas,
    Kentucky,
    Louisiana,
    Maine,
    Maryland,
    Massachusetts,
    Michigan,
    Minnesota,
    Mississippi,
    Missouri,
    Montana,
    Nebraska,
    Nevada,
    NewHampshire,
    NewJersey,
    NewMexico,
    NewYork,
    NorthCarolina,
    NorthDakota,
    Ohio,
    Oklahoma,
    Oregon,
    Pennsylvania,
    RhodeIsland,
    SouthCarolina,
    SouthDakota,
    Tennessee,
    Texas,
    Utah,
    Vermont,
    Virginia,
    Washington,
    WestVirginia,
    Wisconsin,
    Wyoming,
}

impl TryFrom<State> for StateCode {
    type Error = String;

    fn try_from(value: State) -> Result<Self, Self::Error> {
        match value {
            State(1) => Ok(StateCode::Alabama),
            State(2) => Ok(StateCode::Alaska),
            State(4) => Ok(StateCode::Arizona),
            State(5) => Ok(StateCode::Arkansas),
            State(6) => Ok(StateCode::California),
            State(8) => Ok(StateCode::Colorado),
            State(9) => Ok(StateCode::Connecticut),
            State(10) => Ok(StateCode::Delaware),
            State(11) => Ok(StateCode::DistrictOfColumbia),
            State(12) => Ok(StateCode::Florida),
            State(13) => Ok(StateCode::Georgia),
            State(15) => Ok(StateCode::Hawaii),
            State(16) => Ok(StateCode::Idaho),
            State(17) => Ok(StateCode::Illinois),
            State(18) => Ok(StateCode::Indiana),
            State(19) => Ok(StateCode::Iowa),
            State(20) => Ok(StateCode::Kansas),
            State(21) => Ok(StateCode::Kentucky),
            State(22) => Ok(StateCode::Louisiana),
            State(23) => Ok(StateCode::Maine),
            State(24) => Ok(StateCode::Maryland),
            State(25) => Ok(StateCode::Massachusetts),
            State(26) => Ok(StateCode::Michigan),
            State(27) => Ok(StateCode::Minnesota),
            State(28) => Ok(StateCode::Mississippi),
            State(29) => Ok(StateCode::Missouri),
            State(30) => Ok(StateCode::Montana),
            State(31) => Ok(StateCode::Nebraska),
            State(32) => Ok(StateCode::Nevada),
            State(33) => Ok(StateCode::NewHampshire),
            State(34) => Ok(StateCode::NewJersey),
            State(35) => Ok(StateCode::NewMexico),
            State(36) => Ok(StateCode::NewYork),
            State(37) => Ok(StateCode::NorthCarolina),
            State(38) => Ok(StateCode::NorthDakota),
            State(39) => Ok(StateCode::Ohio),
            State(40) => Ok(StateCode::Oklahoma),
            State(41) => Ok(StateCode::Oregon),
            State(42) => Ok(StateCode::Pennsylvania),
            State(44) => Ok(StateCode::RhodeIsland),
            State(45) => Ok(StateCode::SouthCarolina),
            State(46) => Ok(StateCode::SouthDakota),
            State(47) => Ok(StateCode::Tennessee),
            State(48) => Ok(StateCode::Texas),
            State(49) => Ok(StateCode::Utah),
            State(50) => Ok(StateCode::Vermont),
            State(51) => Ok(StateCode::Virginia),
            State(53) => Ok(StateCode::Washington),
            State(54) => Ok(StateCode::WestVirginia),
            State(55) => Ok(StateCode::Wisconsin),
            State(56) => Ok(StateCode::Wyoming),
            _ => Err(format!("unknown FIPS state code {}", value.geoid_string())),
        }
    }
}

impl TryFrom<Geoid> for StateCode {
    type Error = String;

    fn try_from(value: Geoid) -> Result<Self, Self::Error> {
        match value.to_state() {
            Geoid::State(s) => s.try_into(),
            _ => Err(String::from("internal error")),
        }
    }
}

impl From<StateCode> for State {
    fn from(val: StateCode) -> Self {
        match val {
            StateCode::Alabama => State(1),
            StateCode::Alaska => State(2),
            StateCode::Arizona => State(4),
            StateCode::Arkansas => State(5),
            StateCode::California => State(6),
            StateCode::Colorado => State(8),
            StateCode::Connecticut => State(9),
            StateCode::Delaware => State(10),
            StateCode::DistrictOfColumbia => State(11),
            StateCode::Florida => State(12),
            StateCode::Georgia => State(13),
            StateCode::Hawaii => State(15),
            StateCode::Idaho => State(16),
            StateCode::Illinois => State(17),
            StateCode::Indiana => State(18),
            StateCode::Iowa => State(19),
            StateCode::Kansas => State(20),
            StateCode::Kentucky => State(21),
            StateCode::Louisiana => State(22),
            StateCode::Maine => State(23),
            StateCode::Maryland => State(24),
            StateCode::Massachusetts => State(25),
            StateCode::Michigan => State(26),
            StateCode::Minnesota => State(27),
            StateCode::Mississippi => State(28),
            StateCode::Missouri => State(29),
            StateCode::Montana => State(30),
            StateCode::Nebraska => State(31),
            StateCode::Nevada => State(32),
            StateCode::NewHampshire => State(33),
            StateCode::NewJersey => State(34),
            StateCode::NewMexico => State(35),
            StateCode::NewYork => State(36),
            StateCode::NorthCarolina => State(37),
            StateCode::NorthDakota => State(38),
            StateCode::Ohio => State(39),
            StateCode::Oklahoma => State(40),
            StateCode::Oregon => State(41),
            StateCode::Pennsylvania => State(42),
            StateCode::RhodeIsland => State(44),
            StateCode::SouthCarolina => State(45),
            StateCode::SouthDakota => State(46),
            StateCode::Tennessee => State(47),
            StateCode::Texas => State(48),
            StateCode::Utah => State(49),
            StateCode::Vermont => State(50),
            StateCode::Virginia => State(51),
            StateCode::Washington => State(53),
            StateCode::WestVirginia => State(54),
            StateCode::Wisconsin => State(55),
            StateCode::Wyoming => State(56),
        }
    }
}

impl StateCode {
    pub const ALL: [StateCode; 51] = [
        StateCode::Alabama,
        StateCode::Alaska,
        StateCode::Arizona,
        StateCode::Arkansas,
        StateCode::California,
        StateCode::Colorado,
        StateCode::Connecticut,
        StateCode::Delaware,
        StateCode::DistrictOfColumbia,
        StateCode::Florida,
        StateCode::Georgia,
        StateCode::Hawaii,
        StateCode::Idaho,
        StateCode::Illinois,
        StateCode::Indiana,
        StateCode::Iowa,
        StateCode::Kansas,
        StateCode::Kentucky,
        StateCode::Louisiana,
        StateCode::Maine,
        StateCode::Maryland,
        StateCode::Massachusetts,
        StateCode::Michigan,
        StateCode::Minnesota,
        StateCode::Mississippi,
        StateCode::Missouri,
        StateCode::Montana,
        StateCode::Nebraska,
        StateCode::Nevada,
        StateCode::NewHampshire,
        StateCode::NewJersey,
        StateCode::NewMexico,
        StateCode::NewYork,
        StateCode::NorthCarolina,
        StateCode::NorthDakota,
        StateCode::Ohio,
        StateCode::Oklahoma,
        StateCode::Oregon,
        StateCode::Pennsylvania,
        StateCode::RhodeIsland,
        StateCode::SouthCarolina,
        StateCode::SouthDakota,
        StateCode::Tennessee,
        StateCode::Texas,
        StateCode::Utah,
        StateCode::Vermont,
        StateCode::Virginia,
        StateCode::Washington,
        StateCode::WestVirginia,
        StateCode::Wisconsin,
        StateCode::Wyoming,
    ];

    /// a two-letter state abbreviation
    pub fn to_state_abbreviation(&self) -> String {
        match self {
            StateCode::Alabama => String::from("AL"),
            StateCode::Alaska => String::from("AK"),
            StateCode::Arizona => String::from("AZ"),
            StateCode::Arkansas => String::from("AR"),
            StateCode::California => String::from("CA"),
            StateCode::Colorado => String::from("CO"),
            StateCode::Connecticut => String::from("CT"),
            StateCode::Delaware => String::from("DE"),
            StateCode::DistrictOfColumbia => String::from("DC"),
            StateCode::Florida => String::from("FL"),
            StateCode::Georgia => String::from("GA"),
            StateCode::Hawaii => String::from("HI"),
            StateCode::Idaho => String::from("ID"),
            StateCode::Illinois => String::from("IL"),
            StateCode::Indiana => String::from("IN"),
            StateCode::Iowa => String::from("IA"),
            StateCode::Kansas => String::from("KS"),
            StateCode::Kentucky => String::from("Ky"),
            StateCode::Louisiana => String::from("LA"),
            StateCode::Maine => String::from("ME"),
            StateCode::Maryland => String::from("MD"),
            StateCode::Massachusetts => String::from("MA"),
            StateCode::Michigan => String::from("MI"),
            StateCode::Minnesota => String::from("MN"),
            StateCode::Mississippi => String::from("MS"),
            StateCode::Missouri => String::from("MO"),
            StateCode::Montana => String::from("MT"),
            StateCode::Nebraska => String::from("NE"),
            StateCode::Nevada => String::from("NV"),
            StateCode::NewHampshire => String::from("NH"),
            StateCode::NewJersey => String::from("NJ"),
            StateCode::NewMexico => String::from("NM"),
            StateCode::NewYork => String::from("NY"),
            StateCode::NorthCarolina => String::from("NC"),
            StateCode::NorthDakota => String::from("ND"),
            StateCode::Ohio => String::from("OH"),
            StateCode::Oklahoma => String::from("OK"),
            StateCode::Oregon => String::from("OR"),
            StateCode::Pennsylvania => String::from("PA"),
            StateCode::RhodeIsland => String::from("RI"),
            StateCode::SouthCarolina => String::from("SC"),
            StateCode::SouthDakota => String::from("SD"),
            StateCode::Tennessee => String::from("TN"),
            StateCode::Texas => String::from("TX"),
            StateCode::Utah => String::from("UT"),
            StateCode::Vermont => String::from("VT"),
            StateCode::Virginia => String::from("VA"),
            StateCode::Washington => String::from("WA"),
            StateCode::WestVirginia => String::from("WV"),
            StateCode::Wisconsin => String::from("WI"),
            StateCode::Wyoming => String::from("WY"),
        }
    }

    pub fn to_fips_string(&self) -> String {
        match self {
            StateCode::Alabama => String::from("01"),
            StateCode::Alaska => String::from("02"),
            StateCode::Arizona => String::from("04"),
            StateCode::Arkansas => String::from("05"),
            StateCode::California => String::from("06"),
            StateCode::Colorado => String::from("08"),
            StateCode::Connecticut => String::from("09"),
            StateCode::Delaware => String::from("10"),
            StateCode::DistrictOfColumbia => String::from("11"),
            StateCode::Florida => String::from("12"),
            StateCode::Georgia => String::from("13"),
            StateCode::Hawaii => String::from("15"),
            StateCode::Idaho => String::from("16"),
            StateCode::Illinois => String::from("17"),
            StateCode::Indiana => String::from("18"),
            StateCode::Iowa => String::from("19"),
            StateCode::Kansas => String::from("20"),
            StateCode::Kentucky => String::from("21"),
            StateCode::Louisiana => String::from("22"),
            StateCode::Maine => String::from("23"),
            StateCode::Maryland => String::from("24"),
            StateCode::Massachusetts => String::from("25"),
            StateCode::Michigan => String::from("26"),
            StateCode::Minnesota => String::from("27"),
            StateCode::Mississippi => String::from("28"),
            StateCode::Missouri => String::from("29"),
            StateCode::Montana => String::from("30"),
            StateCode::Nebraska => String::from("31"),
            StateCode::Nevada => String::from("32"),
            StateCode::NewHampshire => String::from("33"),
            StateCode::NewJersey => String::from("34"),
            StateCode::NewMexico => String::from("35"),
            StateCode::NewYork => String::from("36"),
            StateCode::NorthCarolina => String::from("37"),
            StateCode::NorthDakota => String::from("38"),
            StateCode::Ohio => String::from("39"),
            StateCode::Oklahoma => String::from("40"),
            StateCode::Oregon => String::from("41"),
            StateCode::Pennsylvania => String::from("42"),
            StateCode::RhodeIsland => String::from("44"),
            StateCode::SouthCarolina => String::from("45"),
            StateCode::SouthDakota => String::from("46"),
            StateCode::Tennessee => String::from("47"),
            StateCode::Texas => String::from("48"),
            StateCode::Utah => String::from("49"),
            StateCode::Vermont => String::from("50"),
            StateCode::Virginia => String::from("51"),
            StateCode::Washington => String::from("53"),
            StateCode::WestVirginia => String::from("54"),
            StateCode::Wisconsin => String::from("55"),
            StateCode::Wyoming => String::from("56"),
        }
    }

    pub fn to_full_name(&self) -> String {
        match self {
            StateCode::Alabama => String::from("Alabama"),
            StateCode::Alaska => String::from("Alaska"),
            StateCode::Arizona => String::from("Arizona"),
            StateCode::Arkansas => String::from("Arkansas"),
            StateCode::California => String::from("California"),
            StateCode::Colorado => String::from("Colorado"),
            StateCode::Connecticut => String::from("Connecticut"),
            StateCode::Delaware => String::from("Delaware"),
            StateCode::DistrictOfColumbia => String::from("DistrictOfColumbia"),
            StateCode::Florida => String::from("Florida"),
            StateCode::Georgia => String::from("Georgia"),
            StateCode::Hawaii => String::from("Hawaii"),
            StateCode::Idaho => String::from("Idaho"),
            StateCode::Illinois => String::from("Illinois"),
            StateCode::Indiana => String::from("Indiana"),
            StateCode::Iowa => String::from("Iowa"),
            StateCode::Kansas => String::from("Kansas"),
            StateCode::Kentucky => String::from("Kentucky"),
            StateCode::Louisiana => String::from("Louisiana"),
            StateCode::Maine => String::from("Maine"),
            StateCode::Maryland => String::from("Maryland"),
            StateCode::Massachusetts => String::from("Massachusetts"),
            StateCode::Michigan => String::from("Michigan"),
            StateCode::Minnesota => String::from("Minnesota"),
            StateCode::Mississippi => String::from("Mississippi"),
            StateCode::Missouri => String::from("Missouri"),
            StateCode::Montana => String::from("Montana"),
            StateCode::Nebraska => String::from("Nebraska"),
            StateCode::Nevada => String::from("Nevada"),
            StateCode::NewHampshire => String::from("NewHampshire"),
            StateCode::NewJersey => String::from("NewJersey"),
            StateCode::NewMexico => String::from("NewMexico"),
            StateCode::NewYork => String::from("NewYork"),
            StateCode::NorthCarolina => String::from("NorthCarolina"),
            StateCode::NorthDakota => String::from("NorthDakota"),
            StateCode::Ohio => String::from("Ohio"),
            StateCode::Oklahoma => String::from("Oklahoma"),
            StateCode::Oregon => String::from("Oregon"),
            StateCode::Pennsylvania => String::from("Pennsylvania"),
            StateCode::RhodeIsland => String::from("RhodeIsland"),
            StateCode::SouthCarolina => String::from("SouthCarolina"),
            StateCode::SouthDakota => String::from("SouthDakota"),
            StateCode::Tennessee => String::from("Tennessee"),
            StateCode::Texas => String::from("Texas"),
            StateCode::Utah => String::from("Utah"),
            StateCode::Vermont => String::from("Vermont"),
            StateCode::Virginia => String::from("Virginia"),
            StateCode::Washington => String::from("Washington"),
            StateCode::WestVirginia => String::from("WestVirginia"),
            StateCode::Wisconsin => String::from("Wisconsin"),
            StateCode::Wyoming => String::from("Wyoming"),
        }
    }
}