Struct gix_fs::SharedFileSnapshotMut
source · pub struct SharedFileSnapshotMut<T: Debug>(pub MutableOnDemand<Option<SharedFileSnapshot<T>>>);
Expand description
Use this type for fields in structs that are to store the FileSnapshot
, typically behind an OwnShared
.
Note that the resource itself is behind another OwnShared
to allow it to be used without holding any kind of lock, hence
without blocking updates while it is used.
Tuple Fields§
§0: MutableOnDemand<Option<SharedFileSnapshot<T>>>
Implementations§
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new instance of this type.
Useful in case Default::default()
isn’t working for some reason.
sourcepub fn force_refresh<E>(
&self,
open: impl FnOnce() -> Result<Option<(SystemTime, T)>, E>,
) -> Result<(), E>
pub fn force_refresh<E>( &self, open: impl FnOnce() -> Result<Option<(SystemTime, T)>, E>, ) -> Result<(), E>
Refresh state
forcefully by re-open
ing the resource. Note that open()
returns None
if the resource isn’t
present on disk, and that it’s critical that the modified time is obtained before opening the resource.
sourcepub fn recent_snapshot<E>(
&self,
current_modification_time: impl FnMut() -> Option<SystemTime>,
open: impl FnOnce() -> Result<Option<T>, E>,
) -> Result<Option<SharedFileSnapshot<T>>, E>
pub fn recent_snapshot<E>( &self, current_modification_time: impl FnMut() -> Option<SystemTime>, open: impl FnOnce() -> Result<Option<T>, E>, ) -> Result<Option<SharedFileSnapshot<T>>, E>
Assure that the resource in state
is up-to-date by comparing the current_modification_time
with the one we know in state
and by acting accordingly.
Returns the potentially updated/reloaded resource if it is still present on disk, which then represents a snapshot that is up-to-date
in that very moment, or None
if the underlying file doesn’t exist.
Note that even though this is racy, each time a request is made there is a chance to see the actual state.