guibranco / viacep-rs

🇧🇷 :round_pushpin: ViaCEP client wrapper for Rust projects
https://guibranco.github.io/viacep-rs/
MIT License
6 stars 1 forks source link
address api cep code correios fazenda gia hacktoberfest ibge mf postal postalcode viacep webservice ws zip zipcode

ViaCEP Rust client

🇧🇷📍ViaCEP client wrapper for Rust projects.

GitHub last commit (branch) Crates.io wakatime

Maintainability Test Coverage CodeFactor

Service Status
AppVeyor CI Build status
crates.io crates.io

Pure Rust bindings to the ViaCEP API.

Dependencies and support

viacep-rs is intended to work on all tier 1 supported Rust systems:

Minimum Compiler Version

Due to the use of certain features viacep-rs requires rustc version 1.18 or higher.

Getting Started

Add the following to your Cargo.toml

[dependencies]
viacep_rs = "0.2.0"
serde_json = "1.0"

Then in your lib.rs or main.rs file add:

extern crate viacep_rs;

let client = ViaCepClient::new();

// Single Zip Code data 
match client.get_zipcode("03177010") {
    Err(e) => eprintln!("{:?}", e),
    Ok(data) => {
        let cep = data.unwrap();
        println!("IBGE: {} | Address: {} | Neighborhood: {} | City: {} | UF: {}", cep.ibge, cep.address, cep.neighborhood, cep.City, cep.state_initials);
    }
}

//Find by address data
match client.search("SP", "São Paulo", "Paulista") {
    Err(e) => eprintln!("{:?}", e),
    Ok(data) => {
        let addresses = data.unwrap();
        for address in addresses {
            println!("IBGE: {} | Address: {} | City: {} | Zip: {}", address.ibge, address.address, address.city, address.zip);
        }
    }
}

License

Licensed under