Created
August 29, 2023 21:28
-
-
Save n3r0bi0m4n/6519480587f09d9b2d7ee5551b9eec86 to your computer and use it in GitHub Desktop.
dumb rust cout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #![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