1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#![allow(dead_code)]
use crate::{store, Namespace};

#[derive(Clone)]
pub(crate) enum State {
    Loose { store: crate::file::Store },
}

impl crate::Store {
    /// Return a new handle which sees all references if `namespace` is `None` or all read and write operations are limited
    /// to the given `namespace` if `Some`.
    pub fn to_handle(&self) -> store::Handle {
        Self::new_handle_inner(&self.inner, None)
    }

    /// As above, but supports a namespace to be set
    pub fn to_handle_namespaced(&self, namespace: Option<Namespace>) -> store::Handle {
        Self::new_handle_inner(&self.inner, namespace)
    }

    fn new_handle_inner(state: &store::State, namespace: Option<Namespace>) -> store::Handle {
        store::Handle {
            state: match state {
                store::State::Loose { store } => store::handle::State::Loose {
                    store: {
                        let mut store = store.clone();
                        store.namespace = namespace;
                        store
                    },
                },
            },
        }
    }
}

///
pub mod find;

mod iter {
    // impl store::Handle {
    //     pub fn iter<'p, 's>(&'s self, packed: Option<&'p packed::Buffer>) -> std::io::Result<LooseThenPacked<'p, 's>> {
    // }
}