From a25436ac796c6d02732b782f79824ea0864f8e08 Mon Sep 17 00:00:00 2001 From: pretzelhammer <7769424+pretzelhammer@users.noreply.github.com> Date: Thu, 23 Jul 2020 16:22:16 -0400 Subject: [PATCH] change wording --- posts/common-rust-lifetime-misconceptions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/common-rust-lifetime-misconceptions.md b/posts/common-rust-lifetime-misconceptions.md index 239a1d5..040e71e 100644 --- a/posts/common-rust-lifetime-misconceptions.md +++ b/posts/common-rust-lifetime-misconceptions.md @@ -480,7 +480,7 @@ fn main() { } ``` -If we have some struct generic over `'a` we almost never want to write a method with an `&'a mut self` argument. What we're communicating to Rust is _"this method will mutably borrow the struct for the entirety of the struct's lifetime"_. In practice this means Rust's borrow checker will only allow at most one call to `some_method` before the struct becomes permanently mutably borrowed and thus unusable. The use-cases for this are extremely rare but the code above is very easy for confused beginners to write and it compiles. The fix is to not add unnecessary explicit lifetime annotations and let Rust's lifetime elision rules handle it: +If we have some struct generic over `'a` we almost never want to write a method with a `&'a mut self` receiver. What we're communicating to Rust is _"this method will mutably borrow the struct for the entirety of the struct's lifetime"_. In practice this means Rust's borrow checker will only allow at most one call to `some_method` before the struct becomes permanently mutably borrowed and thus unusable. The use-cases for this are extremely rare but the code above is very easy for confused beginners to write and it compiles. The fix is to not add unnecessary explicit lifetime annotations and let Rust's lifetime elision rules handle it: ```rust #[derive(Debug)]