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§
Methods from Deref<Target = Buffer>§
sourcepub fn push_inline<T: Inline>(&mut self, thing: &T) -> &mut Self
pub fn push_inline<T: Inline>(&mut self, thing: &T) -> &mut Self
Append thing
onto the buffer using the Inline
trait
sourcepub fn push<M, T: Pushable<M>>(&mut self, thing: T) -> &mut Self
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 parameterM
(i.e.trait Pushable<M>
) that is not used except to make distinct implementations possible for the same typeimpl<T: Display> Pushable<marker::AsDisplay> for T
impl<T: Inline> Pushable<marker::AsInline> for T
push
is implemented for anyT: Pushable<M>
with anyM
- 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