1
1
use interner::global::{BufferPool, GlobalBuffer, StaticPooledBuffer};
2

            
3
static BUFFER_POOL: BufferPool = BufferPool::new();
4
static STATIC_STRING: StaticPooledBuffer = BUFFER_POOL.get_static(b"a");
5

            
6
1
fn main() {
7
1
    // Get a string from the static instance. This will keep the pooled string
8
1
    // alive for the duration of the process.
9
1
    STATIC_STRING.get();
10
1
    // Request the same string directly from the pool.
11
1
    let a_again = BUFFER_POOL.get(&b"a"[..]);
12
1

            
13
1
    // The two instances are pointing to the same instance.
14
1
    assert!(GlobalBuffer::ptr_eq(&*STATIC_STRING, &a_again));
15

            
16
    // Verify the pool still contains "a" even after dropping our local
17
    // instances. This is due to STATIC_STRING still holding a reference.
18
1
    drop(a_again);
19
1
    let pooled: Vec<GlobalBuffer> = BUFFER_POOL.pooled();
20
1
    assert_eq!(pooled.len(), 1);
21
1
    assert_eq!(pooled[0], &b"a"[..]);
22
1
}
23

            
24
1
#[test]
25
1
fn runs() {
26
1
    main();
27
1
}