Created
July 30, 2018 15:49
-
-
Save rust-play/adac9f30c472054e4674e2fcd973f603 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
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