diff options
Diffstat (limited to 'Shortening the lifetime of borrowed variables before mutating it.md')
-rw-r--r-- | Shortening the lifetime of borrowed variables before mutating it.md | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Shortening the lifetime of borrowed variables before mutating it.md b/Shortening the lifetime of borrowed variables before mutating it.md new file mode 100644 index 0000000..d17506f --- /dev/null +++ b/Shortening the lifetime of borrowed variables before mutating it.md @@ -0,0 +1,9 @@ +[[Creating a reference to a variable is called borrowing]] + +--- + +If a function modifies a borrowed variable, we can try to find a way to shorten the lifetime of the borrow. + +One way would be to clone the value into a new variable and mutate that, but it can be expensive. + +Another way could be to use some property of the variable instead of the variable itself, ie the length of a string.
\ No newline at end of file |