Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. struct Context {
  2. timestamp: u64,
  3. }
  4.  
  5. struct Untrusted;
  6. struct Validated<'c> {
  7. ctx: &'c Context,
  8. }
  9.  
  10. struct User {
  11. counter: u64,
  12. ctx: Context
  13. }
  14.  
  15. impl Context {
  16. fn validate<'c>(&'c self, _input: Untrusted) -> Validated<'c> {
  17. Validated { ctx: self }
  18. }
  19. }
  20.  
  21. impl User {
  22. fn consume<'c>(&'c mut self, valid_input: Validated<'c>) {
  23. self.counter += 1;
  24. }
  25. }
  26.  
  27. fn main() {
  28. let mut user = User{ ctx: Context{timestamp: 42}, counter: 0};
  29. let valid = user.ctx.validate(Untrusted{});
  30. user.consume(valid);
  31. println!("ok")
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement