Skip to main content

TransformingSource

Struct TransformingSource 

Source
pub struct TransformingSource { /* private fields */ }
Expand description

A source that wraps another source and applies a PrettifyMode transform to its bytes. Toggling the mode bumps revision() so the event loop rebuilds the line index. Falls back to passing through the inner bytes if the transform fails to parse, surfacing the error via last_error().

Implementations§

Source§

impl TransformingSource

Source

pub fn wrap(inner: Box<dyn Source>, mode: PrettifyMode) -> Self

Build a wrapping source. The inner is read fully via its current bytes view; the transform runs once. If the transform fails, the cache holds the raw inner bytes and last_error() returns the parse error.

Source

pub fn mode(&self) -> PrettifyMode

Source

pub fn last_error(&self) -> Option<String>

Currently surfaced parse error, if any. Cleared by a successful set_mode or by switching to Off.

Trait Implementations§

Source§

impl Debug for TransformingSource

Source§

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

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

impl Source for TransformingSource

Source§

fn len(&self) -> usize

Source§

fn bytes(&self, range: Range<usize>) -> Cow<'_, [u8]>

Source§

fn is_complete(&self) -> bool

Source§

fn pump(&self)

Read any new bytes that have become available since the last call. Default no-op for static sources. Streaming sources override.
Source§

fn revision(&self) -> u64

Monotonic counter that bumps whenever the source’s content has been replaced wholesale (as opposed to merely appended to). Append-style sources keep this at 0; LiveFileSource increments it on each detected rewrite so the event loop knows to rebuild the line index instead of just folding in new bytes.
Source§

fn prettify_mode(&self) -> Option<PrettifyMode>

Current prettify mode if this source has a TransformingSource wrapper. None means the source is not capable of prettification (e.g. a plain FileSource). Some(Off) means wrapped but currently raw.
Source§

fn prettify_label(&self) -> Option<String>

Status-line label for the active prettify state, e.g. "json" or "json:err". None when there’s no wrapper or the mode is Off without an error.
Source§

fn set_prettify_mode(&self, mode: PrettifyMode)

Switch to a specific prettify mode. No-op for sources without a wrapper. Bumps revision() so callers know to rebuild the line index.
Source§

fn toggle_prettify(&self)

Flip between the current mode and the last active (non-Off) mode. No-op if the source is not wrapped, or if it has never had an active mode (i.e. only ever been raw).
Source§

fn redetect_prettify(&self)

Re-run byte-based content detection and apply the result. Used by the interactive -Pa (“auto”) sub-command. No-op without a wrapper.
Source§

fn is_empty(&self) -> bool

Source§

fn take_rotated(&self) -> bool

Returns true once when the source detected that its backing file was rotated or truncated. Append-style sources always return false. FileSource overrides this and consumes the flag on each call so the app loop only reacts once per event.
Source§

fn path(&self) -> Option<&Path>

Source’s on-disk path, when one exists. Used by the app loop to re-open the source after take_rotated() returns true. None for stdin / mock sources.

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.