diff options
author | Jasper Ras <jras@hostnet.nl> | 2025-08-08 22:44:15 +0200 |
---|---|---|
committer | Jasper Ras <jras@hostnet.nl> | 2025-08-08 22:44:15 +0200 |
commit | 22675cd8dc75d8b8d4b0f818f5b093efbc364802 (patch) | |
tree | 90156d37dccf13f012d535e7d92273259e3d5c17 /Shortening the lifetime of borrowed variables before mutating it.md | |
parent | 295b343aecf330e830d79f06e0efc511e7d76da1 (diff) |
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 |