#serialization #state #abbreviation #name #deserialize #information #info

us-state-info

A Fork of a Rust implementation of the state names & abbreviations for the USA

5 releases

0.2.4 May 9, 2024
0.2.3 May 7, 2024
0.2.2 May 6, 2024
0.2.1 May 6, 2024
0.2.0 May 6, 2024

#658 in Encoding

Download history 26/week @ 2024-07-23 36/week @ 2024-07-30 19/week @ 2024-08-06 3/week @ 2024-08-13 1/week @ 2024-08-20 4/week @ 2024-08-27 6/week @ 2024-09-10 16/week @ 2024-09-17 30/week @ 2024-09-24 28/week @ 2024-10-01 20/week @ 2024-10-08 12/week @ 2024-10-15 13/week @ 2024-10-22 121/week @ 2024-10-29 343/week @ 2024-11-05

495 downloads per month

Apache-2.0

16KB
326 lines

us-state-info

United States Individual State Information [Docs] Apache-2 licensed CI

A Rust implementation of the state names & abbreviations for the USA

Usage

Basic Usage

use us_state_info_rs::State;

fn main() {
    let iowa_state = State::Iowa;
    println!("{}-{}", iowa_state, iowa_state.abbreviation());
}

Serde Serialization and Deserialization

With Serde support enabled, you can serialize and deserialize states. By default, states are serialized to their full names. If you enable the serde_abbreviation feature, they will be serialized to their abbreviations instead.

use serde_json::json;
use us_state_info_rs::State;

fn main() {
    let state = State::California;
    let serialized = serde_json::to_string(&state).unwrap();
    println!("Serialized: {}", serialized); // "California" or "CA" with `serde_abbreviation`

    let deserialized: State = serde_json::from_str(&serialized).unwrap(); // In this crate the deserialization can either be the 2 letter or Full name of the state.
    println!("Deserialized: {}", deserialized);
}

Dependencies

~155KB