Skip to content

Instantly share code, notes, and snippets.

@d-plaindoux
Created May 24, 2019 04:23
Show Gist options
  • Save d-plaindoux/828068cf48bf2ecbebad37ac77765c56 to your computer and use it in GitHub Desktop.
Save d-plaindoux/828068cf48bf2ecbebad37ac77765c56 to your computer and use it in GitHub Desktop.
Implement a trait when another is already implemented
#![allow(dead_code)]
use std::io::{self, Read};
use std::marker::PhantomData;
pub trait Foo<T: Read> {
fn get_mut(&self) -> &mut T;
}
struct FooStruct<T,R> where T:Read, R:Foo<T> {
foo : R,
phantom: PhantomData<T>
}
impl<T,R> Read for FooStruct<T,R> where T:Read, R: Foo<T> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.foo.get_mut().read(buf)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment