Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Context {
- timestamp: u64,
- }
- struct Untrusted;
- struct Validated<'c> {
- ctx: &'c Context,
- }
- struct User {
- counter: u64,
- ctx: Context
- }
- impl Context {
- fn validate<'c>(&'c self, _input: Untrusted) -> Validated<'c> {
- Validated { ctx: self }
- }
- }
- impl User {
- fn consume<'c>(&'c mut self, valid_input: Validated<'c>) {
- self.counter += 1;
- }
- }
- fn main() {
- let mut user = User{ ctx: Context{timestamp: 42}, counter: 0};
- let valid = user.ctx.validate(Untrusted{});
- user.consume(valid);
- println!("ok")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement