pub struct Latest<V = Value> {
pub value: Result<V, String>,
pub took: Duration,
pub read_at: Option<SystemTime>,
pub age: Option<Duration>,
pub freshness: Freshness,
pub refreshing: bool,
}Expand description
The latest reading of one source.
use majordomus_cli::capability::readings::{read, Freshness, Latest, Patience};
use majordomus_cli::synthetic::SyntheticRepository;
let repo = SyntheticRepository::small().unwrap();
let ctx = repo.context().unwrap();
let latest: Latest = read(&ctx, "plan.status", serde_json::json!({}), Patience::WAIT);
// what the source answered, how long that took, when it was read and how it stands
assert!(latest.value.is_ok());
assert!(latest.read_at.is_some() && latest.age.is_some());
assert_eq!(latest.freshness, Freshness::Current);
assert!(latest.took >= std::time::Duration::ZERO);Fields§
§value: Result<V, String>What the source answered, or why it could not. Err for a pending reading too.
took: DurationHow long the executor took to produce this reading.
read_at: Option<SystemTime>When it was read; None while pending.
age: Option<Duration>How long ago that was; None while pending.
freshness: FreshnessHow it stands against the repository as it is now.
refreshing: boolWhether a worker is reading the source again at this moment.
Implementations§
Source§impl<V> Latest<V>
impl<V> Latest<V>
Sourcepub fn catching_up(&self) -> bool
pub fn catching_up(&self) -> bool
Whether a reader should be told that what they see is about to be replaced: the reading is not of the repository as it is now.
use majordomus_cli::capability::readings::{read, Freshness, Patience};
use majordomus_cli::synthetic::SyntheticRepository;
let repo = SyntheticRepository::small().unwrap();
let ctx = repo.context().unwrap();
let mut latest = read(&ctx, "plan.status", serde_json::json!({}), Patience::WAIT);
assert!(!latest.catching_up(), "a current reading is not about to be replaced");
latest.freshness = Freshness::Stale;
assert!(latest.catching_up());
latest.freshness = Freshness::Pending;
assert!(latest.catching_up());Trait Implementations§
Auto Trait Implementations§
impl<V> Freeze for Latest<V>where
V: Freeze,
impl<V> RefUnwindSafe for Latest<V>where
V: RefUnwindSafe,
impl<V> Send for Latest<V>where
V: Send,
impl<V> Sync for Latest<V>where
V: Sync,
impl<V> Unpin for Latest<V>where
V: Unpin,
impl<V> UnsafeUnpin for Latest<V>where
V: UnsafeUnpin,
impl<V> UnwindSafe for Latest<V>where
V: 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
Mutably borrows from an owned value. Read more