Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Foo;
- struct FooBuilder<'a> {
- foo: &'a Foo,
- }
- impl Foo {
- fn build(&self) -> FooBuilder {
- FooBuilder { foo: &self }
- }
- }
- impl<'a> FooBuilder<'a> {
- // correct: other lifetime for self
- fn enable<'b>(&'b mut self) -> &'b mut FooBuilder<'a> {
- self
- }
- // wrong: can only call once
- fn disable(&'a mut self) -> &'a mut FooBuilder {
- self
- }
- }
- fn main() {
- let foo = Foo {};
- let mut builder = foo.build();
- builder.enable();
- builder.disable();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement