pub struct MetricsCache { /* private fields */ }Expand description
Shared read/write handle to a cached ConsoleMetricsReport.
Why: The route handler must never block on an MCP call. The background
poller writes to this cache; route handlers read from it.
What: Wraps Arc<RwLock<Option<ConsoleMetricsReport>>>. None means no
successful poll has completed yet (first boot or service absent).
Test: test_metrics_cache_initialises_empty and
test_metrics_cache_write_read_roundtrip.
Implementations§
Source§impl MetricsCache
impl MetricsCache
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new, empty MetricsCache.
Why: Start empty so the route can distinguish “not yet polled” from a
successful but trivially empty report.
What: Allocates Arc<RwLock<None>>.
Test: test_metrics_cache_initialises_empty.
Sourcepub async fn get(&self) -> Option<ConsoleMetricsReport>
pub async fn get(&self) -> Option<ConsoleMetricsReport>
Read the latest cached report (may be None before the first poll).
Why: Route handlers call this to serve the report without blocking.
What: Acquires a read lock, clones the value, releases the lock.
Test: test_metrics_cache_write_read_roundtrip.
Sourcepub async fn set(&self, report: ConsoleMetricsReport)
pub async fn set(&self, report: ConsoleMetricsReport)
Write a new report into the cache.
Why: The poller calls this after each successful poll.
What: Acquires a write lock, replaces the inner value.
Test: test_metrics_cache_write_read_roundtrip.
Trait Implementations§
Source§impl Clone for MetricsCache
impl Clone for MetricsCache
Source§fn clone(&self) -> MetricsCache
fn clone(&self) -> MetricsCache
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MetricsCache
impl Debug for MetricsCache
Auto Trait Implementations§
impl !RefUnwindSafe for MetricsCache
impl !UnwindSafe for MetricsCache
impl Freeze for MetricsCache
impl Send for MetricsCache
impl Sync for MetricsCache
impl Unpin for MetricsCache
impl UnsafeUnpin for MetricsCache
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,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more