pub struct LevelProfile<S: Storage = Heap> { /* private fields */ }Expand description
A self-contained copy of a timeline’s level line, for display and telemetry.
Holds the breakpoints only (three i64 each), not the impacts, so it is cheap to store,
send or compare. With Fixed<N> storage it never allocates and
always has room for the profile of an N-impact timeline.
Implementations§
Source§impl<S: Storage> LevelProfile<S>
impl<S: Storage> LevelProfile<S>
Sourcepub fn encoded_len(&self) -> usize
pub fn encoded_len(&self) -> usize
The number of bytes encode writes.
Sourcepub fn encode(&self, out: &mut [u8]) -> Result<usize, Error>
pub fn encode(&self, out: &mut [u8]) -> Result<usize, Error>
Writes the profile into out and returns the number of bytes written; see the
codec module for the format.
§Errors
Error::BufferTooSmall if out is shorter than encoded_len;
nothing is written then. Error::Overflow if the breakpoint count exceeds u32.
Sourcepub fn decode_in(bytes: &[u8]) -> Result<Self, Error>
pub fn decode_in(bytes: &[u8]) -> Result<Self, Error>
Reads a profile written by encode, into storage S.
§Errors
Error::Malformedif the magic, the length or the content is wrong (breakpoints must be strictly increasing in tick).Error::UnsupportedVersionfor another format version.Error::ChecksumMismatchif the bytes were corrupted.Error::CapacityExceededorError::OutOfMemoryifScannot hold the breakpoints.
Source§impl LevelProfile
impl LevelProfile
Source§impl<S: Storage> LevelProfile<S>
impl<S: Storage> LevelProfile<S>
Sourcepub const fn start(&self) -> Tick
pub const fn start(&self) -> Tick
The first tick of the profile, the start of the timeline it was exported from.
Sourcepub fn breakpoints(&self) -> impl Iterator<Item = Breakpoint> + '_
pub fn breakpoints(&self) -> impl Iterator<Item = Breakpoint> + '_
The breakpoints in time order, the first at start.
Sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Always false: a profile has at least the breakpoint at its start.
Sourcepub fn level_at(&self, t: Tick) -> Result<Level, Error>
pub fn level_at(&self, t: Tick) -> Result<Level, Error>
The level at tick t, as the exported timeline would report it.
Costs O(log n) for n breakpoints.
§Errors
Error::BeforeStartiftprecedes the start.Error::Overflowif the level does not fit aLevel.