Struct shawshank::Solitary [] [src]

pub struct Solitary<O: StableAddress<Target=R>, R: ?Sized + StableAddress = O::Target, I = usize, M = HashMap<&'static R::Target, I>>(pub Prison<O, I, M>);

Specialization of Prison where O::Target: StableAddress.

Example: if O = Arc<Vec<u8>>, then O::Target = Vec<u8>. Therefore, the map M can be HashMap<&'static u8, usize>, rather than the HashMap<&'static Vec<u8>, usize> that Prison would use. intern can similarly accept &'a [u8] instead of &'a Vec<u8>.

Methods

impl<O, R, I, M> Solitary<O, R, I, M> where O: StableAddress<Target=R>, R: 'static + StableAddress, I: Copy + ToPrimitive + FromPrimitive + Bounded, M: Map<Key=&'static R::Target, Value=I>
[src]

Analogue of intern.

use std::collections::HashMap;
use std::sync::Arc;

let mut p = shawshank::byte_solitary();
assert_eq!(p.intern(&[1,2,3][..]), Ok(0));
assert_eq!(p.intern(vec![1,2,3]), Ok(0));

Analogue of disintern.

use std::collections::HashMap;
use std::ops::Deref;
use std::sync::Arc;

let mut p = shawshank::byte_solitary();
assert_eq!(p.intern(&[1,2,3][..]), Ok(0));
assert_eq!(p.disintern(0).unwrap().deref().deref(), &[1,2,3]);

Analogue of resolve.

use std::collections::HashMap;
use std::sync::Arc;

let mut p = shawshank::byte_solitary();
assert_eq!(p.intern(&[1,2,3][..]), Ok(0));
let s1: &Vec<u8> = p.resolve(0).unwrap();
let s1: &Arc<Vec<u8>> = p.resolve(0).unwrap();

Analogue of shrink.