Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created January 24, 2020 16:00
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 rust-play/e9967935bd1038f32ea55bb3731bacd0 to your computer and use it in GitHub Desktop.
Save rust-play/e9967935bd1038f32ea55bb3731bacd0 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
use std::ops::Index;
struct Foo<T> {
val: T,
}
impl<T> Index<usize> for (&Foo<T>, &str) {
type Output = T;
fn index(&self, _: usize) -> &T {
self.0.val
}
}
fn main() {
let foo: Foo<u32> = Foo { val: 123 };
println!("{}", foo[0]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment