#[allow(unused_imports)]
use core::{convert::TryFrom, file, line, stringify};
pub use no_std_io::io::*;
pub use crate::{dbg, eprint, eprintln, print, println};
#[doc(hidden)]
#[allow(missing_debug_implementations)]
pub struct __SerialWriter(i32);
impl core::fmt::Write for __SerialWriter {
#[inline]
fn write_str(&mut self, s: &str) -> core::fmt::Result {
__println(self.0, s)
}
}
impl __SerialWriter {
#[inline]
pub const fn new(err: bool) -> __SerialWriter {
__SerialWriter(if err { 2 } else { 1 })
}
#[inline]
pub fn write_fmt(&mut self, args: core::fmt::Arguments<'_>) -> core::fmt::Result {
core::fmt::Write::write_fmt(self, args)
}
#[inline]
pub fn write_str(&mut self, s: &str) -> core::fmt::Result {
__println(self.0, s)
}
#[inline]
pub fn write_nl(&mut self) -> core::fmt::Result {
__println(self.0, "\n")
}
}
#[doc(hidden)]
#[inline]
pub fn __println(handle: i32, msg: &str) -> core::fmt::Result {
let msg = msg.as_bytes();
let mut written = 0;
while written < msg.len() {
match unsafe { write(handle, &msg[written..]) } {
None | Some(0) => break,
Some(res) => written += res,
}
}
Ok(())
}
unsafe fn write(handle: i32, bytes: &[u8]) -> Option<usize> {
usize::try_from(unsafe {
pros_sys::write(
handle,
bytes.as_ptr().cast::<core::ffi::c_void>(),
bytes.len(),
)
})
.ok()
}
#[macro_export]
macro_rules! println {
() => { $crate::println!("") };
($($arg:tt)*) => {
{
#[allow(unused_must_use)]
{
let mut stm = $crate::io::__SerialWriter::new(false);
stm.write_fmt(format_args!($($arg)*));
stm.write_nl();
}
}
};
}
#[macro_export]
macro_rules! print {
($($arg:tt)*) => {
{
#[allow(unused_must_use)]
{
let mut stm = $crate::io::__SerialWriter::new(false);
stm.write_fmt(format_args!($($arg)*));
}
}
};
}
#[macro_export]
macro_rules! eprintln {
() => { $crate::eprintln!("") };
($($arg:tt)*) => {
{
#[allow(unused_must_use)]
{
let mut stm = $crate::io::__SerialWriter::new(true);
stm.write_fmt(format_args!($($arg)*));
stm.write_nl();
}
}
};
}
#[macro_export]
macro_rules! eprint {
($($arg:tt)*) => {
{
#[allow(unused_must_use)]
{
let mut stm = $crate::io::__SerialWriter::new(true);
stm.write_fmt(format_args!($($arg)*));
}
}
};
}
#[macro_export]
macro_rules! dbg {
() => {
$crate::eprintln!("[{}:{}]", $file!(), $line!())
};
($val:expr $(,)?) => {
match $val {
tmp => {
$crate::eprintln!("[{}:{}] {} = {:#?}", file!(), line!(), stringify!($val), &tmp);
tmp
}
}
};
($($val:expr),+ $(,)?) => {
($($crate::dbg!($val)),+,)
};
}