From 0a12425a6478f243fcc0e6b10de707fc919aa62a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Gonz=C3=A1lez?= Date: Tue, 22 Aug 2023 22:05:23 +0200 Subject: [PATCH] fix: correct typos in mem-replace.md (#371) * fix: fix typos in mem-replace.md --- src/idioms/mem-replace.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/idioms/mem-replace.md b/src/idioms/mem-replace.md index ab2d431..28d0d27 100644 --- a/src/idioms/mem-replace.md +++ b/src/idioms/mem-replace.md @@ -20,7 +20,7 @@ enum MyEnum { fn a_to_b(e: &mut MyEnum) { if let MyEnum::A { name, x: 0 } = e { - // this takes out our `name` and put in an empty String instead + // This takes out our `name` and puts in an empty String instead // (note that empty strings don't allocate). // Then, construct the new enum variant (which will // be assigned to `*e`). @@ -69,8 +69,8 @@ into our `MyEnum::B`, but that would be an instance of the anti-pattern. Anyway, we can avoid the extra allocation by changing `e` with only a mutable borrow. -`mem::take` lets us swap out the value, replacing it with it's default value, -and returning the previous value. For `String`, the default value is an empty +`mem::take` lets us swap out the value, replacing it with its default value, and +returning the previous value. For `String`, the default value is an empty `String`, which does not need to allocate. As a result, we get the original `name` *as an owned value*. We can then wrap this in another enum.