Created
July 17, 2019 18:18
-
-
Save bddap/b198128d3b17b2827b37135017614be2 to your computer and use it in GitHub Desktop.
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
// Request -> Bids -> BidChoosen -> ProductionStarted -> ProductionComplete | |
// \<-----/ | |
struct Request { | |
purchaser: EntityId, | |
id: JobId, | |
quantity: u64, | |
reserve_price_per_unit: u64, | |
} | |
impl Request { | |
fn new(purchaser: EntityId, quantity: u64, reserve_price_per_unit: u64) -> Request { | |
Request { | |
purchaser: EntityId, | |
id: generate_job_id(), | |
quantity: u64, | |
reserve_price_per_unit: u64, | |
} | |
} | |
fn auction(self) -> Bids { | |
Bids { | |
request: self, | |
bids: Vec::new(), | |
} | |
} | |
} | |
struct Bid { | |
producer: EntityId, | |
offer: u64, | |
} | |
struct Bids { | |
request: Request, | |
bids: Vec<Bid>, | |
} | |
impl Bids { | |
fn bid(self, bid: Bid) -> Bids { | |
let mut slef = self; | |
slef.bids.push(bid); | |
slef | |
} | |
fn choose_bid(self, bid: Bids) -> BidChoosen { | |
BidChoosen { | |
request: self.request, | |
bid, | |
} | |
} | |
} | |
struct BidChoosen { | |
bids: Bids, | |
choosen_bid: Bid, | |
} | |
impl BidChoosen { | |
fn start(self) -> BidChoosen { | |
BidChoosen(self) | |
} | |
} | |
struct ProductionStarted(BidChoosen); | |
impl BidChoosen { | |
fn complete(self) -> ProductionComplete { | |
ProductionComplete(self) | |
} | |
} | |
struct ProductionComplete(ProductionStarted); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment