SHARE
TWEET

Untitled

a guest Jun 18th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct Context {
  2. }
  3. trait Cx {
  4. }
  5. impl Cx for Context {
  6. }
  7.  
  8. impl Context {
  9.     fn getGadget(&self) -> String {
  10.         String::from("World!")
  11.     }
  12. }
  13.  
  14. fn main() {
  15.     let cx = Context {};
  16.     let model = ProductInstance::getModel(cx);
  17.     println!("{}", model.boop());
  18. }
  19.  
  20. // Model stuff
  21.  
  22. trait ModelInstance {
  23.     fn getContext(&self) -> &Context;
  24.     fn getModel(cx: Context) -> Self;
  25. }
  26.  
  27. struct ProductInstance {
  28.     cx: Context
  29. }
  30. impl ProductInstance {
  31.     fn boop(&self) -> String {
  32.         format!("Hello, {}", self.getContext().getGadget())
  33.     }
  34. }
  35.  
  36. impl ModelInstance for ProductInstance {
  37.     fn getContext(&self) -> &Context {
  38.         &self.cx
  39.     }
  40.     fn getModel(cx: Context) -> ProductInstance {
  41.         ProductInstance { cx }
  42.     }
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top