#string-interning #intern #string #atom #interning #validation

string-intern

Another implementation of string interning. Unique features: allows to define a type for each kind of interned values and a validator for the values of that type.

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

#2075 in Encoding

Download history 24/week @ 2024-02-04 7/week @ 2024-02-18 54/week @ 2024-02-25 10/week @ 2024-03-03 25/week @ 2024-03-10 4/week @ 2024-03-17

93 downloads per month
Used in 2 crates

MIT/Apache

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

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