Skip to content

Instantly share code, notes, and snippets.

@bddap
Created July 17, 2019 18:18
Show Gist options
  • Save bddap/b198128d3b17b2827b37135017614be2 to your computer and use it in GitHub Desktop.
Save bddap/b198128d3b17b2827b37135017614be2 to your computer and use it in GitHub Desktop.
// 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