Skip to content

guibranco/viacep-sdk-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

120 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

ViaCEP Rust client

πŸ‡§πŸ‡·πŸ“ ViaCEP client wrapper for Rust projects.

GitHub last commit (branch) wakatime

Maintainability Test Coverage CodeFactor

Service Status
crates.io Crates.io

Pure Rust bindings to the ViaCEP API.

Dependencies and support

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

  • macOS
  • Linux
  • Windows

Minimum Compiler Version

viacep requires rustc 1.56 or higher (edition 2021).

Getting Started

Add the following to your Cargo.toml:

[dependencies]
viacep = "1.0.0"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }

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

use viacep::ViaCepClient;

let client = ViaCepClient::new();

// Single Zip Code lookup
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
        );
    }
}

// Search by address
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 the MIT license (LICENSE or http://opensource.org/licenses/MIT).