8 releases
Uses old Rust 2015
0.1.7 | Aug 1, 2017 |
---|---|
0.1.6 | Jul 13, 2017 |
0.1.5 | May 31, 2017 |
0.1.4 | Dec 27, 2016 |
0.1.3 | Nov 21, 2016 |
#2243 in Encoding
103 downloads per month
Used in 2 crates
13KB
294 lines
String Interning Library
Status: | Beta |
---|---|
Documentation: | http://docs.rs/string-intern/ |
Another implementation of string interning for rust. Features:
- allows to define a type for each kind of interned values and a validator for the values of that type.
- implements rustc_serialize::Encodable/Decodable
- implements serde support
License
Licensed under either of
- Apache License, Version 2.0, (./LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (./LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
lib.rs
:
String interning for rust
Example
use string_intern::{Validator, Symbol};
struct UserIdSymbol;
// This symbol may contain anything
impl Validator for UserIdSymbol {
// Use an error from standard library to make example shorter
type Err = ::std::string::ParseError;
fn validate_symbol(val: &str) -> Result<(), Self::Err> {
Ok(())
}
}
/// Actual symbol type you will use in code
type UserId = Symbol<UserIdSymbol>;
// Create from const (panics on invalid input)
let x = UserId::from("user1");
// Create from user input
let y: UserId = format!("user{}", 1).parse().unwrap();
// Both point to the same bytes
assert!(x[..].as_bytes() as *const _ == y[..].as_bytes() as *const _);
Dependencies
~345–590KB
~13K SLoC