Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::marker::PhantomData;
- struct Bar<'a, S> {
- phantom: PhantomData<S>,
- data: &'a mut Vec<u8>,
- }
- impl<'a, S> Bar<'a, S>
- where
- S: Foo<'a>,
- {
- fn new(data: &'a mut Vec<u8>) -> Self {
- Bar {
- phantom: PhantomData,
- data,
- }
- }
- fn foo_method(&mut self) {
- S::new().do_stuff(&mut self.data);
- }
- }
- trait Foo<'a> {
- fn new() -> Self;
- fn do_stuff(&self, _name: &'a mut Vec<u8>);
- }
- struct FooA {}
- impl<'a> Foo<'a> for FooA {
- fn new() -> FooA {
- FooA {}
- }
- fn do_stuff(&self, _name: &'a mut Vec<u8>) {}
- }
- fn main() {
- let mut v = Vec::<u8>::new();
- Bar::<FooA>::new(&mut v).foo_method();
- }
Add Comment
Please, Sign In to add comment