1
1
use std::borrow::Cow;
2
use std::path::Path;
3

            
4
use interner::global::{GlobalPath, PathPool, StaticPooledPath};
5

            
6
static PATH_POOL: PathPool = PathPool::new();
7
// Because there is no way to get a Path in a const context, we have to use the
8
// lazy option, which is a little more verbose due to it accepting both owned or
9
1
static STATIC_PATH: StaticPooledPath = PATH_POOL.get_static_with(|| Cow::Borrowed(Path::new("a")));
10

            
11
1
fn main() {
12
1
    // Get a path from the static instance. This will keep the pooled path
13
1
    // alive for the duration of the process.
14
1
    STATIC_PATH.get();
15
1
    // Request the same path directly from the pool.
16
1
    let a_again = PATH_POOL.get(Path::new("a"));
17
1

            
18
1
    // The two instances are pointing to the same instance.
19
1
    assert!(GlobalPath::ptr_eq(&*STATIC_PATH, &a_again));
20

            
21
    // Verify the pool still contains "a" even after dropping our local
22
    // instances. This is due to STATIC_PATH still holding a reference.
23
1
    drop(a_again);
24
1
    let pooled: Vec<GlobalPath> = PATH_POOL.pooled();
25
1
    assert_eq!(pooled.len(), 1);
26
1
    assert_eq!(pooled[0], Path::new("a"));
27
1
}
28

            
29
1
#[test]
30
1
fn runs() {
31
1
    main();
32
1
}