///
/// The changesets are the results of altering a tracker implementation (`T`).
#[derive(Debug)]
-pub struct Store<'a, C> {
- magic: &'a [u8],
+pub struct Store<C> {
+ magic_len: usize,
db_file: File,
marker: PhantomData<C>,
}
-impl<'a, C> PersistBackend<C> for Store<'a, C>
+impl<C> PersistBackend<C> for Store<C>
where
C: Append + serde::Serialize + serde::de::DeserializeOwned,
{
}
}
-impl<'a, C> Store<'a, C>
+impl<C> Store<C>
where
C: Append + serde::Serialize + serde::de::DeserializeOwned,
{
/// the `Store` in the future with [`open`].
///
/// [`open`]: Store::open
- pub fn create_new<P>(magic: &'a [u8], file_path: P) -> Result<Self, FileError>
+ pub fn create_new<P>(magic: &[u8], file_path: P) -> Result<Self, FileError>
where
P: AsRef<Path>,
{
.open(file_path)?;
f.write_all(magic)?;
Ok(Self {
- magic,
+ magic_len: magic.len(),
db_file: f,
marker: Default::default(),
})
/// [`FileError::InvalidMagicBytes`] error variant will be returned.
///
/// [`create_new`]: Store::create_new
- pub fn open<P>(magic: &'a [u8], file_path: P) -> Result<Self, FileError>
+ pub fn open<P>(magic: &[u8], file_path: P) -> Result<Self, FileError>
where
P: AsRef<Path>,
{
}
Ok(Self {
- magic,
+ magic_len: magic.len(),
db_file: f,
marker: Default::default(),
})
///
/// [`open`]: Store::open
/// [`create_new`]: Store::create_new
- pub fn open_or_create_new<P>(magic: &'a [u8], file_path: P) -> Result<Self, FileError>
+ pub fn open_or_create_new<P>(magic: &[u8], file_path: P) -> Result<Self, FileError>
where
P: AsRef<Path>,
{
/// always iterate over all entries until `None` is returned if you want your next write to go
/// at the end; otherwise, you will write over existing entries.
pub fn iter_changesets(&mut self) -> EntryIter<C> {
- EntryIter::new(self.magic.len() as u64, &mut self.db_file)
+ EntryIter::new(self.magic_len as u64, &mut self.db_file)
}
/// Loads all the changesets that have been stored as one giant changeset.
local_chain::ChangeSet,
indexed_tx_graph::ChangeSet<A, keychain::ChangeSet<Keychain>>,
);
-pub type Database<'m, C> = Persist<Store<'m, C>, C>;
+pub type Database<C> = Persist<Store<C>, C>;
#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
}
#[allow(clippy::type_complexity)]
-pub fn init<'m, CS: clap::Subcommand, S: clap::Args, C>(
- db_magic: &'m [u8],
+pub fn init<CS: clap::Subcommand, S: clap::Args, C>(
+ db_magic: &[u8],
db_default_path: &str,
) -> anyhow::Result<(
Args<CS, S>,
KeyMap,
KeychainTxOutIndex<Keychain>,
- Mutex<Database<'m, C>>,
+ Mutex<Database<C>>,
C,
)>
where
index.add_keychain(Keychain::Internal, internal_descriptor);
}
- let mut db_backend = match Store::<'m, C>::open_or_create_new(db_magic, &args.db_path) {
+ let mut db_backend = match Store::<C>::open_or_create_new(db_magic, &args.db_path) {
Ok(db_backend) => db_backend,
// we cannot return `err` directly as it has lifetime `'m`
Err(err) => return Err(anyhow::anyhow!("failed to init db backend: {:?}", err)),