use std::fmt::Display;
use std::io::Write;
use std::ops::Shl;
use super::as_write::AsWrite;
pub struct OStream<W: Write>(W);
impl<W: Write> OStream<W> {
#[inline]
pub const fn new(writer: W) -> Self {
OStream(writer)
}
#[inline]
pub fn into_innter(self) -> W {
self.0
}
}
impl<W: Write> AsWrite for OStream<W> {
#[inline]
fn as_write(&mut self) -> impl Write {
&mut self.0
}
}
impl<T: Display, W: Write> Shl<T> for OStream<W> {
type Output = Self;
#[inline]
fn shl(mut self, _rhs: T) -> Self::Output {
let _ = &mut self << _rhs;
self
}
}
impl<T: Display, W: Write> Shl<T> for &mut OStream<W> {
type Output = Self;
#[inline]
fn shl(self, _rhs: T) -> Self::Output {
ostream_impl(&mut self.0, _rhs);
self
}
}
#[inline]
pub(crate) fn ostream_impl(write: &mut impl Write, display: impl Display) {
write!(write, "{display}").unwrap();
}