use crate::*;
#[derive(Debug)]
#[allow(clippy::exhaustive_structs)] pub struct CoreWriteAsPartsWrite<W: fmt::Write + ?Sized>(pub W);
impl<W: fmt::Write + ?Sized> fmt::Write for CoreWriteAsPartsWrite<W> {
#[inline]
fn write_str(&mut self, s: &str) -> fmt::Result {
self.0.write_str(s)
}
#[inline]
fn write_char(&mut self, c: char) -> fmt::Result {
self.0.write_char(c)
}
}
impl<W: fmt::Write + ?Sized> PartsWrite for CoreWriteAsPartsWrite<W> {
type SubPartsWrite = CoreWriteAsPartsWrite<W>;
#[inline]
fn with_part(
&mut self,
_part: Part,
mut f: impl FnMut(&mut Self::SubPartsWrite) -> fmt::Result,
) -> fmt::Result {
f(self)
}
}
#[derive(Debug)]
#[allow(clippy::exhaustive_structs)] pub struct WithPart<T: ?Sized> {
pub part: Part,
pub writeable: T,
}
impl<T: Writeable + ?Sized> Writeable for WithPart<T> {
#[inline]
fn write_to<W: fmt::Write + ?Sized>(&self, sink: &mut W) -> fmt::Result {
self.writeable.write_to(sink)
}
#[inline]
fn write_to_parts<W: PartsWrite + ?Sized>(&self, sink: &mut W) -> fmt::Result {
sink.with_part(self.part, |w| self.writeable.write_to_parts(w))
}
#[inline]
fn writeable_length_hint(&self) -> LengthHint {
self.writeable.writeable_length_hint()
}
fn writeable_borrow(&self) -> Option<&str> {
self.writeable.writeable_borrow()
}
#[inline]
#[cfg(feature = "alloc")]
fn write_to_string(&self) -> Cow<'_, str> {
self.writeable.write_to_string()
}
}
impl<T: Writeable + ?Sized> fmt::Display for WithPart<T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Writeable::write_to(&self, f)
}
}