use crate::TryWriteable;
use crate::Writeable;
use core::fmt;
#[derive(Debug)]
#[allow(clippy::exhaustive_structs)] pub struct Concat<A, B>(pub A, pub B);
impl<A, B> Writeable for Concat<A, B>
where
A: Writeable,
B: Writeable,
{
#[inline]
fn write_to<W: fmt::Write + ?Sized>(&self, sink: &mut W) -> fmt::Result {
self.0.write_to(sink)?;
self.1.write_to(sink)
}
#[inline]
fn write_to_parts<S: crate::PartsWrite + ?Sized>(&self, sink: &mut S) -> fmt::Result {
self.0.write_to_parts(sink)?;
self.1.write_to_parts(sink)
}
#[inline]
fn writeable_length_hint(&self) -> crate::LengthHint {
self.0.writeable_length_hint() + self.1.writeable_length_hint()
}
}
impl<A, B, E> TryWriteable for Concat<A, B>
where
A: TryWriteable<Error = E>,
B: TryWriteable<Error = E>,
{
type Error = E;
#[inline]
fn try_write_to<W: fmt::Write + ?Sized>(
&self,
sink: &mut W,
) -> Result<Result<(), Self::Error>, fmt::Error> {
if let Err(e) = self.0.try_write_to(sink)? {
return Ok(Err(e));
}
self.1.try_write_to(sink)
}
#[inline]
fn try_write_to_parts<S: crate::PartsWrite + ?Sized>(
&self,
sink: &mut S,
) -> Result<Result<(), Self::Error>, fmt::Error> {
if let Err(e) = self.0.try_write_to_parts(sink)? {
return Ok(Err(e));
}
self.1.try_write_to_parts(sink)
}
#[inline]
fn writeable_length_hint(&self) -> crate::LengthHint {
self.0.writeable_length_hint() + self.1.writeable_length_hint()
}
}
impl<A, B> fmt::Display for Concat<A, B>
where
A: Writeable,
B: Writeable,
{
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.write_to(f)?;
self.1.write_to(f)
}
}
#[macro_export]
#[doc(hidden)] macro_rules! __concat_writeable {
($x:expr) => ($x);
($x:expr, $($y:expr),+) => (
$crate::adapters::Concat($x, $crate::concat_writeable!($($y),+))
)
}
#[doc(inline)]
pub use __concat_writeable as concat_writeable;