2023-11-28 00:43:35 +00:00
|
|
|
//! Public macros for porvide.d for users to be able implement our `io::Write` trait.
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
/// Because we cannot provide a blanket implementation of [`std::io::Write`] for all implementers
|
|
|
|
/// of this crate's `io::Write` trait, we provide this macro instead.
|
|
|
|
///
|
|
|
|
/// This macro will implement `Write` given a `write` and `flush` fn, either by implementing the
|
|
|
|
/// crate's native `io::Write` trait directly, or a more generic trait from `std` for users using
|
|
|
|
/// that feature. In any case, this crate's `io::Write` feature will be implemented for the given
|
|
|
|
/// type, even if indirectly.
|
|
|
|
#[cfg(not(feature = "std"))]
|
|
|
|
macro_rules! impl_write {
|
|
|
|
($ty: ty, $write_fn: expr, $flush_fn: expr $(, $bounded_ty: ident : $bounds: path),*) => {
|
2023-11-28 00:49:26 +00:00
|
|
|
impl<$($bounded_ty: $bounds),*> $crate::Write for $ty {
|
2023-11-28 00:43:35 +00:00
|
|
|
#[inline]
|
2023-11-28 00:49:26 +00:00
|
|
|
fn write(&mut self, buf: &[u8]) -> $crate::Result<usize> {
|
2023-11-28 00:43:35 +00:00
|
|
|
$write_fn(self, buf)
|
|
|
|
}
|
|
|
|
#[inline]
|
2023-11-28 00:49:26 +00:00
|
|
|
fn flush(&mut self) -> $crate::Result<()> {
|
2023-11-28 00:43:35 +00:00
|
|
|
$flush_fn(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
/// Because we cannot provide a blanket implementation of [`std::io::Write`] for all implementers
|
|
|
|
/// of this crate's `io::Write` trait, we provide this macro instead.
|
|
|
|
///
|
|
|
|
/// This macro will implement `Write` given a `write` and `flush` fn, either by implementing the
|
|
|
|
/// crate's native `io::Write` trait directly, or a more generic trait from `std` for users using
|
|
|
|
/// that feature. In any case, this crate's `io::Write` feature will be implemented for the given
|
|
|
|
/// type, even if indirectly.
|
|
|
|
#[cfg(feature = "std")]
|
|
|
|
macro_rules! impl_write {
|
|
|
|
($ty: ty, $write_fn: expr, $flush_fn: expr $(, $bounded_ty: ident : $bounds: path),*) => {
|
|
|
|
impl<$($bounded_ty: $bounds),*> std::io::Write for $ty {
|
|
|
|
#[inline]
|
|
|
|
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
|
|
|
|
$write_fn(self, buf)
|
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
fn flush(&mut self) -> std::io::Result<()> {
|
|
|
|
$flush_fn(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|