Skip to content

Instantly share code, notes, and snippets.

@n3r0bi0m4n
Created August 29, 2023 21:28
Show Gist options
  • Select an option

  • Save n3r0bi0m4n/6519480587f09d9b2d7ee5551b9eec86 to your computer and use it in GitHub Desktop.

Select an option

Save n3r0bi0m4n/6519480587f09d9b2d7ee5551b9eec86 to your computer and use it in GitHub Desktop.
dumb rust cout
#![allow(non_camel_case_types)]
#![allow(unused_must_use)]
use std::fmt;
use std::ops::Shl;
struct cout;
struct endl;
impl fmt::Display for endl {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
write!(f, "\n")
}
}
macro_rules! impl_cout {
($($t:ty),*) => {
$(impl Shl<$t> for cout {
type Output = Self;
fn shl(self, input: $t) -> Self::Output {
print!("{}", input);
self
}
})*
}
}
impl_cout!{&str, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, String, endl}
fn main() {
cout << "hello! " << endl << 1 << endl << String::from("world") << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment