#string-interning #servo #cache #atom #part

string_cache

作为 Servo 项目的组成部分开发的 Rust 字符串池库

67 个版本

0.8.7 2023年3月7日
0.8.5 2023年2月22日
0.8.4 2022年3月27日
0.8.2 2021年10月12日
0.1.10 2015年7月30日

#4 in 缓存

Download history • Rust 包仓库 297734/week @ 2024-04-22 • Rust 包仓库 264884/week @ 2024-04-29 • Rust 包仓库 268169/week @ 2024-05-06 • Rust 包仓库 293563/week @ 2024-05-13 • Rust 包仓库 306267/week @ 2024-05-20 • Rust 包仓库 300133/week @ 2024-05-27 • Rust 包仓库 314981/week @ 2024-06-03 • Rust 包仓库 317445/week @ 2024-06-10 • Rust 包仓库 313131/week @ 2024-06-17 • Rust 包仓库 310865/week @ 2024-06-24 • Rust 包仓库 286732/week @ 2024-07-01 • Rust 包仓库 308294/week @ 2024-07-08 • Rust 包仓库 315886/week @ 2024-07-15 • Rust 包仓库 346539/week @ 2024-07-22 • Rust 包仓库 340295/week @ 2024-07-29 • Rust 包仓库 353215/week @ 2024-08-05 • Rust 包仓库

1,376,174 每月下载量
用于 2,207 个 Crates (50 直接)

MIT/Apache

32KB
482

string-cache

Build Status

文档

作为 Servo 项目的组成部分开发的 Rust 字符串池库。

简单用法

Cargo.toml

[dependencies]
string_cache = "0.8"

lib.rs

extern crate string_cache;
use string_cache::DefaultAtom as Atom;

使用静态原子

Cargo.toml

[package]
build = "build.rs"

[dependencies]
string_cache = "0.8"

[build-dependencies]
string_cache_codegen = "0.5"

build.rs

extern crate string_cache_codegen;

use std::env;
use std::path::Path;

fn main() {
    string_cache_codegen::AtomType::new("foo::FooAtom", "foo_atom!")
        .atoms(&["foo", "bar"])
        .write_to_file(&Path::new(&env::var("OUT_DIR").unwrap()).join("foo_atom.rs"))
        .unwrap()
}

lib.rs

extern crate string_cache;

mod foo {
    include!(concat!(env!("OUT_DIR"), "/foo_atom.rs"));
}

生成的代码将定义一个 FooAtom 类型和一个 foo_atom! 宏。这个宏可以在表达式或模式中使用,字符串列表在 build.rs 中列出。例如

fn compute_something(input: &foo::FooAtom) -> u32 {
    match *input {
        foo_atom!("foo") => 1,
        foo_atom!("bar") => 2,
        _ => 3,
    }
}

依赖关系

~0.5–5.5MB
~17K SLoC