Struct conciliator::core::NoNewLine

source ·
pub struct NoNewLine<'s> { /* private fields */ }
Expand description

Wrap a Buffer to print it without a newline when dropped

This struct is obtained from Line::no_newline and apart from not appending the newline automatically, it is equivalent to Line. This means it also prints itself when dropped.

Implementations§

source§

impl<'s> NoNewLine<'s>

source

pub fn print(self)

Print this NoNewLine into the Stream. This is equivalent to dropping.

source

pub fn discard(self)

Discard and drop this buffer without printing it

This also elides flushing the Stream.

Methods from Deref<Target = Buffer>§

source

pub fn push_inline<T: Inline>(&mut self, thing: &T) -> &mut Self

Append thing onto the buffer using the Inline trait

source

pub fn push<M, T: Pushable<M>>(&mut self, thing: T) -> &mut Self

Append thing onto the buffer using either Inline or Display, doesn’t work if both are implemented for T

Pushable is blanket-implemented for both Inline and Display types. This would normally not be possible, because both blanket implementations could apply to the same type, thereby causing a conflict (Rust does not have any specialization or way to express where T: NOT Trait). So instead, this uses a trick that relies on a “marker type” being inferred.

This workaround is described in detail on Pushable, but in short:

  • Pushable has a type parameter M (i.e. trait Pushable<M>) that is not used except to make distinct implementations possible for the same type
  • impl<T: Display> Pushable<marker::AsDisplay> for T
  • impl<T: Inline> Pushable<marker::AsInline> for T
  • push is implemented for any T: Pushable<M> with any M
  • when there is only one applicable implementation, the marker type M can be inferred and won’t need to be specified
  • Surprisingly, it just works!

If, however, there are multiple applicable implementations (i.e. for a type implements Inline and Display), the type cannot be inferred: type annotations needed. In this case, it is easier to just use the more specific function instead of bothering with the type annotations. (For the time being, the marker types are private, so type annotations are also impossible.)

 use conciliator::{Conciliator, Wrap};
 let con = conciliator::init();
 con.line(..)
     .push("Test") // &str,
     .push(123)    // i32 and
     .push(' ')    // char all implement Display
     .push(Wrap::Alpha(":^)")); // Wrap implements Inline

Trait Implementations§

source§

impl<'s> Deref for NoNewLine<'s>

§

type Target = Buffer

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'s> DerefMut for NoNewLine<'s>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<'s> Drop for NoNewLine<'s>

source§

fn drop(&mut self)

The NoNewLine prints itself to the Stream when dropped

This flushes the output stream manually because it cannot rely on the newline triggering “automatic” flushing.

Auto Trait Implementations§

§

impl<'s> RefUnwindSafe for NoNewLine<'s>

§

impl<'s> Send for NoNewLine<'s>

§

impl<'s> Sync for NoNewLine<'s>

§

impl<'s> Unpin for NoNewLine<'s>

§

impl<'s> UnwindSafe for NoNewLine<'s>

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>,

§

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>,

§

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.