Skip to content

Instantly share code, notes, and snippets.

@tamamu
Created July 3, 2016 15:41
Show Gist options
  • Save tamamu/7ec2242d95a81990be129cd9ed7bcdc9 to your computer and use it in GitHub Desktop.
Save tamamu/7ec2242d95a81990be129cd9ed7bcdc9 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