Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created December 7, 2018 22:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/51060e1843b5a837fe38f812a5a374f6 to your computer and use it in GitHub Desktop.
Save rust-play/51060e1843b5a837fe38f812a5a374f6 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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