const_lookup_map 0.1.0

Rust map that can be defined in a const context.
Documentation
  • Coverage
  • 50%
    5 out of 10 items documented2 out of 7 items with examples
  • Size
  • Source code size: 8.56 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.01 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • thomas9911/const_lookup_map
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • thomas9911

const_lookup_map

Rust map that can be defined in a const context.

There are two ways to create it:

use const_lookup_map::{ConstLookup, lookup};

const LOOKUP_MACRO: ConstLookup<3, &str, &str> = lookup! {
    "best" => "better",
    "test" => "testing",
    "guessed" => "guessing",
};
use const_lookup_map::ConstLookup;

pub const LOOKUP: ConstLookup<4, &str, &str> = ConstLookup::new(
    ["bye", "hallo", "hey", "test"],
    [
        "bye.example.com",
        "hallo.example.com",
        "hey.example.com",
        "test.example.com",
    ],
);

One note; The keys should be in order/sorted because the get method will use this to effienctly get the value. See [ConstLookup::check_sorted]

Usage

use const_lookup_map::{ConstLookup, lookup};

const LOOKUP: ConstLookup<3, &str, &str> = lookup! {
    "best" => "better",
    "test" => "testing",
    "guessed" => "guessing",
};

fn my_function() {
  assert_eq!(LOOKUP.get(&"best"), Some(&"better"));
  assert_eq!(LOOKUP[&"best"], "better");
}