1
1
use interner::global::{GlobalString, StaticPooledString, StringPool};
2

            
3
static STRING_POOL: StringPool = StringPool::new();
4
static STATIC_STRING: StaticPooledString = STRING_POOL.get_static("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 = STRING_POOL.get("a");
12
1

            
13
1
    // The two instances are pointing to the same instance.
14
1
    assert!(GlobalString::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<GlobalString> = STRING_POOL.pooled();
20
1
    assert_eq!(pooled.len(), 1);
21
1
    assert_eq!(pooled[0], "a");
22
1
}
23

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