-
-
Save carllerche/76605b9f7c724a61a11224a36d29e023 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub trait Service { | |
type Request; | |
fn call(&self, request: Self::Request); | |
} | |
pub trait OptionService: Service<Request = Option<<Self as OptionService>::Some>> { | |
type Some; | |
} | |
impl<T, A> OptionService for T | |
where T: Service<Request = Option<A>> | |
{ | |
type Some = A; | |
} | |
pub struct SomeString; | |
impl Service for SomeString { | |
type Request = Option<String>; | |
fn call(&self, request: Self::Request) { | |
println!("GOT: {:?}", request); | |
} | |
} | |
fn call<T: OptionService<Some = String>>(s: &T) { | |
s.call(Some("foo".to_string())); | |
} | |
pub fn main() { | |
call(&SomeString); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rustc blanket.rs | |
error[E0275]: overflow evaluating the requirement `<Self as OptionService>::Some` | |
--> blanket.rs:7:1 | |
| | |
7 | / pub trait OptionService: Service<Request = Option<<Self as OptionService>::Some>> { | |
8 | | type Some; | |
9 | | } | |
| |_^ | |
| | |
= note: required because of the requirements on the impl of `OptionService` for `Self` | |
error: aborting due to previous error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment