Debian Codegraph @

third_party/rust/rkv/src/backend/impl_safe/database.rs

raw
1 // Copyright 2018-2019 Mozilla
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 // this file except in compliance with the License. You may obtain a copy of the
5 // License at http://www.apache.org/licenses/LICENSE-2.0
6 // Unless required by applicable law or agreed to in writing, software distributed
7 // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8 // CONDITIONS OF ANY KIND, either express or implied. See the License for the
9 // specific language governing permissions and limitations under the License.
10
11 use id_arena::Id;
12 use serde_derive::{Deserialize, Serialize};
13
14 use super::{snapshot::Snapshot, DatabaseFlagsImpl};
15 use crate::backend::traits::BackendDatabase;
16
17 #[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
18 pub struct DatabaseImpl(pub(crate) Id<Database>);
19
20 impl BackendDatabase for DatabaseImpl {}
21
22 #[derive(Debug, Serialize, Deserialize)]
23 pub struct Database {
24 snapshot: Snapshot,
25 }
26
27 impl Database {
28 pub(crate) fn new(flags: Option<DatabaseFlagsImpl>, snapshot: Option<Snapshot>) -> Database {
29 Database {
30 snapshot: snapshot.unwrap_or_else(|| Snapshot::new(flags)),
31 }
32 }
33
34 pub(crate) fn snapshot(&self) -> Snapshot {
35 self.snapshot.clone()
36 }
37
38 pub(crate) fn replace(&mut self, snapshot: Snapshot) -> Snapshot {
39 std::mem::replace(&mut self.snapshot, snapshot)
40 }
41 }