Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
trait Query<'a, 'b: 'a, X: 'b, Y: 'a> {
fn execute(&self, f: X) -> Y;
struct ToBeQueried {
inner: String
struct GetInnerSlice;
impl<'a, 'b: 'a> Query<'a, 'b, &'b ToBeQueried, &'a str> for GetInnerSlice {
fn execute(&self, f: &'b ToBeQueried) -> &'a str {
struct QueryWrapper<Q> {
query: Q
impl<Q> QueryWrapper<Q> {
fn new(query: Q) -> Self {
QueryWrapper { query: query }
trait ExecuteQuery<'a, 'b: 'a, X: 'b, Y: 'a, Q: Query<'a, 'b, X, Y>> {
fn query(&self) -> &Q;
fn execute_query(&self, o: X) -> Y {
impl<'a, 'b: 'a, X: 'b, Y: 'a, Q: Query<'a, 'b, X, Y>> ExecuteQuery<'a, 'b, X, Y, Q> for QueryWrapper<Q> {
fn query(&self) -> &Q {
fn apply_query<'a, 'b: 'a>(a: &'b ToBeQueried) -> &'a str {
let wrapper = QueryWrapper::new(GetInnerSlice);
fn main() {
let mut string = ToBeQueried::default();
string.inner = "foo".to_string();
println!("{}", apply_query(&string));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.