flagcdn 1.0.0

A simple library for generating CDN links to country flag images in various sizes and formats.
Documentation
  • Coverage
  • 4%
    2 out of 50 items documented0 out of 4 items with examples
  • Size
  • Source code size: 6.57 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.45 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • INikonI/flagcdn-rs
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • INikonI

flagcdn

It's a simple Rust library for generating CDN links to country flag images in various sizes and formats.

It uses https://flagcdn.com API (powered by https://flagpedia.net)

You can use it for embedding on your website/web-app or for programmatically download to keep flags in your projects up-to-date.

Usage example

use flagcdn::{flag_url, size::FixedHeight, Format};
use reqwest::blocking::Client;
use std::fs::File;

fn main() {
    let country_code = "JP";
    let format = Format::JPEG;

    let http = Client::new();
    let medium_japan_flag_url = flag_url(FixedHeight::XXL, country_code, format);
    let image_bytes = http
        .get(medium_japan_flag_url)
        .send()
        .expect("Failed to get image over http")
        .bytes()
        .expect("Failed to get response body as bytes");
    let mut file = File::create(format!("{country_code}.{format}")).expect("Failed to create file");
    file.write(&image_bytes)
        .expect("Failed to write image bytes to file");
    file.flush().expect("Failed to flush file");
}