[][src]Struct rmesg::RMesgLinesIterator

pub struct RMesgLinesIterator { /* fields omitted */ }

While reading the kernel log buffer is very useful in and of itself (expecially when running the CLI), a lot more value is unlocked when it can be tailed line-by-line.

This struct provides the facilities to do that. It implements an iterator to easily iterate indefinitely over the lines.

IMPORTANT NOTE: This iterator makes a best-effort attempt at eliminating duplicate lines so that it can only provide newer lines upon each iteration. The way it accomplishes this is by using the timestamp field, to track the last-seen timestamp of a line already buffered, and this only consuming lines past that timestamp on each poll.

The timestamp may not always be set in kernel logs. The iterator will ignore lines without a timestamp. It is left to the consumers of this struct to ensure the timestamp is set, if they wish for lines to not be ignored. In order to aid this, two functions are provided in this crate to check kernel_log_timestamps_enabled and to set or unset kernel_log_timestamps_enable.

The UX is left to the consumer.

Implementations

impl RMesgLinesIterator[src]

pub fn with_options(
    clear: bool,
    poll_interval: Duration
) -> Result<RMesgLinesIterator, RMesgError>
[src]

Create a new RMesgLinesIterator with two specific options clear: bool specifies Whether or not to clear the buffer after every read. poll_interval: Duration specifies the interval after which to poll the buffer for new lines

Choice of these parameters affects how the iterator behaves significantly.

When clear is set, the buffer is cleared after each read. This means other utilities on the system that may also be reading the buffer will miss lines/data as it may be cleared before they can read it. This is a destructive option provided for completeness.

The poll interval determines how frequently RMesgLinesIterator polls for new content. If the poll interval is too short, the iterator will eat up resources for no benefit. If it is too long, then any lines that showed up and were purged between the two polls will be lost.

This crate exports a constant SUGGESTED_POLL_INTERVAL which contains the recommended default when in doubt.

Trait Implementations

impl Iterator for RMesgLinesIterator[src]

Trait to iterate over lines of the kernel log buffer.

type Item = Result<String, RMesgError>

The type of the elements being iterated over.

fn next(&mut self) -> Option<Self::Item>[src]

This is a blocking call, and will use the calling thread to perform polling NOT a thread-safe method either. It is suggested this method be always blocked on to ensure no messages are missed.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.