Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created July 30, 2018 15:49
Show Gist options
  • Save rust-play/adac9f30c472054e4674e2fcd973f603 to your computer and use it in GitHub Desktop.
Save rust-play/adac9f30c472054e4674e2fcd973f603 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
pub trait Point{
type Identifier: PartialEq;
fn id(&self) -> Self::Identifier;
}
#[derive(Debug)]
pub struct Connection<T: Point> {
pub to: T
}
impl<T: Point> Connection<T> {
pub fn is_connected_to(&self, point: T) -> bool
{
self.to.id() == point.id()
}
}
pub fn main() {
#[derive(Debug)]
struct SimplePoint;
impl Point for SimplePoint{
type Identifier = char;
fn id(&self) -> char { return 'A' }
}
let a = SimplePoint {};
let conn = Connection {
to: a
};
println!("conn: {:?}", conn);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment