pub struct Proxy<T> { /* private fields */ }
Expand description
An object database to read from any implementation but write to memory. Previously written objects can be returned from memory upon query, which makes the view of objects consistent. In-Memory objects can be disabled by taking out its storage. From there in-memory object can also be persisted one by one.
It’s possible to turn off the memory by removing it from the instance.
Implementations§
Source§impl<T> Proxy<T>
impl<T> Proxy<T>
Lifecycle
Sourcepub fn new(odb: T, object_hash: Kind) -> Proxy<T>
pub fn new(odb: T, object_hash: Kind) -> Proxy<T>
Create a new instance using odb
as actual object provider, with an empty in-memory store for
objects that are to be written.
Use object_hash
to determine the kind of hash to produce when writing new objects.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Turn ourselves into our inner object database, while deallocating objects stored in memory.
Sourcepub fn with_write_passthrough(self) -> Self
pub fn with_write_passthrough(self) -> Self
Strip object memory off this instance, which means that writes will go through to the inner object database right away. This mode makes the proxy fully transparent.
Source§impl<T> Proxy<T>
impl<T> Proxy<T>
Memory Access
Sourcepub fn take_object_memory(&mut self) -> Option<Storage>
pub fn take_object_memory(&mut self) -> Option<Storage>
Take all the objects in memory so far, with the memory storage itself and return it.
The instance will remain in a state where it won’t be able to store objects in memory at all, they will now be stored in the underlying object database. This mode makes the proxy fully transparent.
To avoid that, use reset_object_memory()
or return the storage
using set_object_memory()
.
Sourcepub fn set_object_memory(&mut self, new: Storage) -> Option<Storage>
pub fn set_object_memory(&mut self, new: Storage) -> Option<Storage>
Set the object storage to contain only new
objects, and return whichever objects were there previously.
Sourcepub fn enable_object_memory(&mut self) -> &mut Self
pub fn enable_object_memory(&mut self) -> &mut Self
If objects aren’t written to memory yet, this will happen after the call.
Otherwise, no change will be performed.
Sourcepub fn reset_object_memory(&self) -> Option<Storage>
pub fn reset_object_memory(&self) -> Option<Storage>
Reset the internal storage to be empty, and return the previous storage, with all objects it contained.
Note that this does nothing if this instance didn’t contain object memory in the first place. In that case, set it explicitly.
Sourcepub fn num_objects_in_memory(&self) -> usize
pub fn num_objects_in_memory(&self) -> usize
Return the amount of objects currently stored in memory.
Trait Implementations§
Source§impl<T> Header for Proxy<T>where
T: FindHeader,
impl<T> Header for Proxy<T>where
T: FindHeader,
Source§impl<T> Write for Proxy<T>where
T: Write,
impl<T> Write for Proxy<T>where
T: Write,
Source§fn write_stream(
&self,
kind: Kind,
size: u64,
from: &mut dyn Read,
) -> Result<ObjectId, Error>
fn write_stream( &self, kind: Kind, size: u64, from: &mut dyn Read, ) -> Result<ObjectId, Error>
write
, but takes an input stream.
This is commonly used for writing blobs directly without reading them to memory first.Auto Trait Implementations§
impl<T> !Freeze for Proxy<T>
impl<T> !RefUnwindSafe for Proxy<T>
impl<T> Send for Proxy<T>where
T: Send,
impl<T> !Sync for Proxy<T>
impl<T> Unpin for Proxy<T>where
T: Unpin,
impl<T> UnwindSafe for Proxy<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, A> DynAccess<T> for A
impl<T, A> DynAccess<T> for A
Source§fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
Access::load
.Source§impl<T> FindExt for T
impl<T> FindExt for T
Source§fn find<'a>(&self, id: &oid, buffer: &'a mut Vec<u8>) -> Result<Data<'a>, Error>
fn find<'a>(&self, id: &oid, buffer: &'a mut Vec<u8>) -> Result<Data<'a>, Error>
try_find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error.Source§fn find_blob<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
) -> Result<BlobRef<'a>, Error>
fn find_blob<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<BlobRef<'a>, Error>
find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired object type.Source§fn find_tree<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
) -> Result<TreeRef<'a>, Error>
fn find_tree<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<TreeRef<'a>, Error>
find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired object type.Source§fn find_commit<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
) -> Result<CommitRef<'a>, Error>
fn find_commit<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<CommitRef<'a>, Error>
find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired object type.Source§fn find_tag<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
) -> Result<TagRef<'a>, Error>
fn find_tag<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<TagRef<'a>, Error>
find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired object type.Source§fn find_commit_iter<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
) -> Result<CommitRefIter<'a>, Error>
fn find_commit_iter<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<CommitRefIter<'a>, Error>
find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired iterator type.Source§fn find_tree_iter<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
) -> Result<TreeRefIter<'a>, Error>
fn find_tree_iter<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<TreeRefIter<'a>, Error>
find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired iterator type.Source§fn find_tag_iter<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
) -> Result<TagRefIter<'a>, Error>
fn find_tag_iter<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<TagRefIter<'a>, Error>
find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired iterator type.