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