Skip to main content

LineBuffer

Struct LineBuffer 

Source
pub(super) struct LineBuffer {
    pub(super) stdout: BytesMut,
    stderr: BytesMut,
}
Expand description

Collects the output of both pipes into whole lines for journald, which writes one entry per line.

A read chunk may end anywhere, in the middle of a line, between “\r” and “\n” or inside a multi byte character. Keeping the incomplete tail until the next chunk of the same pipe arrives avoids split lines and garbled characters. A line which grows beyond LineBuffer::MAX_LINE is written as a partial one, cut at a character boundary, and so is a line which waits too long for its ending, see LineBuffer::flush.

Fields§

§stdout: BytesMut§stderr: BytesMut

Implementations§

Source§

impl LineBuffer

Source

pub(super) const MAX_LINE: usize

Longer lines get written as partial entries.

Source

fn tail(&mut self, pipe: Pipe) -> &mut BytesMut

Source

pub(super) fn has_pending(&self, pipe: Pipe) -> bool

Whether a line of the pipe waits for its ending.

Source

pub(super) fn push<'a>(&mut self, pipe: Pipe, bytes: &'a [u8]) -> Vec<Line<'a>>

Add a chunk and return the lines it completes. The whole lines of the chunk borrow it, only the end of a line which started in an earlier chunk and the start of one which continues in a later one get copied into the buffer of the pipe.

Source

fn cut_long(tail: &mut BytesMut) -> Option<Line<'static>>

Cut a line which grew too long without its ending, see LineBuffer::cut, and release the buffer once empty.

Source

fn cut(tail: &mut BytesMut) -> Line<'static>

Cut the tail at a point which keeps an unfinished multi byte character and a “\r” waiting for its “\n” in the buffer. Invalid bytes are not held back, they would stay in front forever.

Source

fn complete_len(bytes: &[u8]) -> usize

The length of the bytes without the unfinished multi byte character they end with, if any. Only the last character matters, which starts within the last three bytes if it is unfinished, an invalid byte in front of it does not.

Source

fn shrink(tail: &mut BytesMut)

A line longer than a read chunk leaves a large buffer behind, release it once drained. An idle container keeps at most a chunk of it.

Source

pub(super) fn flush(&mut self, pipe: Pipe) -> Vec<Line<'static>>

Return the line which waits for its ending as a partial one. The output paused, a prompt or progress output without a newline would otherwise stay invisible.

Source

pub(super) fn finish(&mut self, pipe: Pipe) -> Vec<Line<'static>>

The output of the pipe ended, return the line which still waits for its ending as a partial one.

Trait Implementations§

Source§

impl Debug for LineBuffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LineBuffer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more