Git Product home page Git Product logo

string-cache's Introduction

string-cache

Build Status

Documentation

A string interning library for Rust, developed as part of the Servo project.

Simple usage

In Cargo.toml:

[dependencies]
string_cache = "0.4"

In lib.rs:

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

With static atoms

In Cargo.toml:

[package]
build = "build.rs"

[dependencies]
string_cache = "0.4"

[build-dependencies]
string_cache_codegen = "0.3"

In 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()
}

In lib.rs:

extern crate string_cache;

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

The generated code will define a FooAtom type and a foo_atom! macro. The macro can be used in expression or patterns, with strings listed in build.rs. For example:

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

string-cache's People

Contributors

aidanhs avatar akosthekiss avatar amarant avatar aroben avatar bholley avatar chris-morgan avatar creativcoder avatar dzbarsky avatar eefriedman avatar frewsxcv avatar glennw avatar gw3583 avatar jdm avatar jxs avatar kichjang avatar kmcallister avatar kroisse avatar manishearth avatar mbrubeck avatar metajack avatar ms2ger avatar mystor avatar notriddle avatar nox avatar paulrouget avatar pcwalton avatar ruuda avatar simonsapin avatar thekk avatar ygg01 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.