Created
January 24, 2020 16:00
-
-
Save rust-play/e9967935bd1038f32ea55bb3731bacd0 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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
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