Skip to content

Instantly share code, notes, and snippets.

@tclh123
Forked from tamamu/iostream.rs
Created August 30, 2019 07:54
Show Gist options
  • Save tclh123/aaed683cd63fb9516695377778313a22 to your computer and use it in GitHub Desktop.
Save tclh123/aaed683cd63fb9516695377778313a22 to your computer and use it in GitHub Desktop.
std::cout (C++) in Rust
use std::ops::Shl;
struct Rsout;
struct Endl;
impl<'a> Shl<&'a str> for Rsout {
type Output = Rsout;
fn shl(self, _rhs: &'a str) -> Rsout {
print!("{}", _rhs);
self
}
}
impl Shl<i32> for Rsout {
type Output = Rsout;
fn shl(self, _rhs: i32) -> Rsout {
print!("{}", _rhs);
self
}
}
impl Shl<Endl> for Rsout {
type Output = Rsout;
fn shl(self, _rhs: Endl) -> Rsout {
print!("\n");
self
}
}
fn main() {
Rsout << "Hello, " << "world!" << Endl;
Rsout << "1 + 2 = " << 1 + 2 << Endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment