Created
December 7, 2018 22:55
-
-
Save rust-play/51060e1843b5a837fe38f812a5a374f6 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
type BarberId= usize; | |
type ShopId = usize; | |
struct Shop { | |
barber: Option<BarberId>, | |
} | |
struct Barber { | |
shop: Option<ShopId>, | |
} | |
struct MyDataStore { | |
barbers: Vec<Barber>, | |
shops: Vec<Shop> | |
} | |
impl MyDataStore { | |
fn add_barber(&mut self, barber: Barber) -> BarberId { | |
let id = self.barbers.len(); | |
self.barbers.push(barber); | |
id | |
} | |
fn add_shop(&mut self, shop: Shop) -> ShopId { | |
let id = self.shops.len(); | |
self.shops.push(shop); | |
id | |
} | |
fn assign_barber_and_shop(&mut self, shop_id: ShopId, barber_id: BarberId) { | |
self.barbers[barber_id].shop = Some(shop_id); | |
self.shops[shop_id].barber = Some(barber_id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment