Skip to content

Commit 0bee46e

Browse files
committed
fix(store): Remove lifetime
Remove gratuitous use of lifetimes in the main persistence struct
1 parent 0a2a570 commit 0bee46e

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

crates/file_store/src/store.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ use crate::{bincode_options, EntryIter, FileError, IterError};
1515
///
1616
/// The changesets are the results of altering a tracker implementation (`T`).
1717
#[derive(Debug)]
18-
pub struct Store<'a, C> {
19-
magic: &'a [u8],
18+
pub struct Store<C> {
19+
magic_len: usize,
2020
db_file: File,
2121
marker: PhantomData<C>,
2222
}
2323

24-
impl<'a, C> PersistBackend<C> for Store<'a, C>
24+
impl<C> PersistBackend<C> for Store<C>
2525
where
2626
C: Append + serde::Serialize + serde::de::DeserializeOwned,
2727
{
@@ -38,7 +38,7 @@ where
3838
}
3939
}
4040

41-
impl<'a, C> Store<'a, C>
41+
impl<C> Store<C>
4242
where
4343
C: Append + serde::Serialize + serde::de::DeserializeOwned,
4444
{
@@ -48,7 +48,7 @@ where
4848
/// the `Store` in the future with [`open`].
4949
///
5050
/// [`open`]: Store::open
51-
pub fn create_new<P>(magic: &'a [u8], file_path: P) -> Result<Self, FileError>
51+
pub fn create_new<P>(magic: &[u8], file_path: P) -> Result<Self, FileError>
5252
where
5353
P: AsRef<Path>,
5454
{
@@ -67,7 +67,7 @@ where
6767
.open(file_path)?;
6868
f.write_all(magic)?;
6969
Ok(Self {
70-
magic,
70+
magic_len: magic.len(),
7171
db_file: f,
7272
marker: Default::default(),
7373
})
@@ -83,7 +83,7 @@ where
8383
/// [`FileError::InvalidMagicBytes`] error variant will be returned.
8484
///
8585
/// [`create_new`]: Store::create_new
86-
pub fn open<P>(magic: &'a [u8], file_path: P) -> Result<Self, FileError>
86+
pub fn open<P>(magic: &[u8], file_path: P) -> Result<Self, FileError>
8787
where
8888
P: AsRef<Path>,
8989
{
@@ -99,7 +99,7 @@ where
9999
}
100100

101101
Ok(Self {
102-
magic,
102+
magic_len: magic.len(),
103103
db_file: f,
104104
marker: Default::default(),
105105
})
@@ -111,7 +111,7 @@ where
111111
///
112112
/// [`open`]: Store::open
113113
/// [`create_new`]: Store::create_new
114-
pub fn open_or_create_new<P>(magic: &'a [u8], file_path: P) -> Result<Self, FileError>
114+
pub fn open_or_create_new<P>(magic: &[u8], file_path: P) -> Result<Self, FileError>
115115
where
116116
P: AsRef<Path>,
117117
{
@@ -132,7 +132,7 @@ where
132132
/// always iterate over all entries until `None` is returned if you want your next write to go
133133
/// at the end; otherwise, you will write over existing entries.
134134
pub fn iter_changesets(&mut self) -> EntryIter<C> {
135-
EntryIter::new(self.magic.len() as u64, &mut self.db_file)
135+
EntryIter::new(self.magic_len as u64, &mut self.db_file)
136136
}
137137

138138
/// Loads all the changesets that have been stored as one giant changeset.

example-crates/example_cli/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub type KeychainChangeSet<A> = (
2929
local_chain::ChangeSet,
3030
indexed_tx_graph::ChangeSet<A, keychain::ChangeSet<Keychain>>,
3131
);
32-
pub type Database<'m, C> = Persist<Store<'m, C>, C>;
32+
pub type Database<C> = Persist<Store<C>, C>;
3333

3434
#[derive(Parser)]
3535
#[clap(author, version, about, long_about = None)]
@@ -646,14 +646,14 @@ where
646646
}
647647

648648
#[allow(clippy::type_complexity)]
649-
pub fn init<'m, CS: clap::Subcommand, S: clap::Args, C>(
650-
db_magic: &'m [u8],
649+
pub fn init<CS: clap::Subcommand, S: clap::Args, C>(
650+
db_magic: &[u8],
651651
db_default_path: &str,
652652
) -> anyhow::Result<(
653653
Args<CS, S>,
654654
KeyMap,
655655
KeychainTxOutIndex<Keychain>,
656-
Mutex<Database<'m, C>>,
656+
Mutex<Database<C>>,
657657
C,
658658
)>
659659
where
@@ -681,7 +681,7 @@ where
681681
index.add_keychain(Keychain::Internal, internal_descriptor);
682682
}
683683

684-
let mut db_backend = match Store::<'m, C>::open_or_create_new(db_magic, &args.db_path) {
684+
let mut db_backend = match Store::<C>::open_or_create_new(db_magic, &args.db_path) {
685685
Ok(db_backend) => db_backend,
686686
// we cannot return `err` directly as it has lifetime `'m`
687687
Err(err) => return Err(anyhow::anyhow!("failed to init db backend: {:?}", err)),

0 commit comments

Comments
 (0)