Skip to content

Instantly share code, notes, and snippets.

@carllerche
Last active November 3, 2017 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carllerche/76605b9f7c724a61a11224a36d29e023 to your computer and use it in GitHub Desktop.
Save carllerche/76605b9f7c724a61a11224a36d29e023 to your computer and use it in GitHub Desktop.
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);
}
$ 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