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

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

#2243 in Encoding

Download history 11/week @ 2024-03-27 60/week @ 2024-04-03 21/week @ 2024-04-10 2/week @ 2024-04-17 6/week @ 2024-04-24 4/week @ 2024-05-08 7/week @ 2024-05-15 16/week @ 2024-05-22 116/week @ 2024-05-29 38/week @ 2024-06-05 37/week @ 2024-06-12 13/week @ 2024-06-19 32/week @ 2024-06-26 24/week @ 2024-07-03 31/week @ 2024-07-10

103 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