pub trait PlatformSampler: Default {
// Required methods
fn sample(&mut self) -> (SystemSnapshot, Vec<Row>);
fn cache_len(&self) -> usize;
fn backend_name() -> &'static str;
// Provided methods
fn set_scan_options(&mut self, _opts: ScanOptions) { ... }
fn supports_threads() -> bool { ... }
}Expand description
A unified sampler interface so the front end does not name a backend.
docs/DESIGN.md §5: selection happens at compile time, so this trait exists
for genericity in tests and for documentation, not for runtime dispatch in
the hot loop.
Required Methods§
Sourcefn sample(&mut self) -> (SystemSnapshot, Vec<Row>)
fn sample(&mut self) -> (SystemSnapshot, Vec<Row>)
Take one sample: host counters plus one row per process.
Sourcefn cache_len(&self) -> usize
fn cache_len(&self) -> usize
Number of cached per-process identity records, for tests and diagnostics.
Sourcefn backend_name() -> &'static str
fn backend_name() -> &'static str
A user-facing name for the backend.
Provided Methods§
Sourcefn set_scan_options(&mut self, _opts: ScanOptions)
fn set_scan_options(&mut self, _opts: ScanOptions)
Tell the sampler what the front end currently needs.
Call this before every sample(). The default implementation ignores it,
which is the right behaviour for a backend with no expensive reads.
Sourcefn supports_threads() -> bool
fn supports_threads() -> bool
Whether this backend can actually enumerate threads.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl PlatformSampler for Sampler
The unified sampler interface.
This was only implemented for the Darwin backend, so on Linux the trait was
declared but never satisfied: gander_core::PlatformSampler described an
interface that did not exist on the platform where it mattered most, and
every use gander_core::PlatformSampler in a Linux-only test was dead
(the inherent sample shadowed it). sample and cache_len now exist only
on the trait, on both platforms, so a caller cannot accidentally depend on a
method that one backend happens to have and the other does not.