Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(core_intrinsics)]
- use std::io::{Stdout, stdout, Write};
- fn print_type_of<T>(_: &T) {
- println!("{}", unsafe { std::intrinsics::type_name::<T>() });
- }
- struct Foo<T> {
- out_sink: T
- }
- impl Foo<Stdout> {
- fn new() -> Self {
- Foo { out_sink: stdout() }
- }
- }
- impl<T: Write> Foo<T> {
- fn with_writer(writer: T) -> Self {
- Foo { out_sink: writer }
- }
- fn testor(&self) {
- print_type_of(&self.out_sink);
- }
- }
- fn main() {
- let bar = Foo::new();
- let baz = Foo::with_writer(Vec::<u8>::new());
- bar.testor();
- baz.testor();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement