From 22675cd8dc75d8b8d4b0f818f5b093efbc364802 Mon Sep 17 00:00:00 2001 From: Jasper Ras Date: Fri, 8 Aug 2025 22:44:15 +0200 Subject: vault backup: 2025-08-08 22:44:15 --- ...ning the lifetime of borrowed variables before mutating it.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Shortening the lifetime of borrowed variables before mutating it.md (limited to 'Shortening the lifetime of borrowed variables before mutating it.md') 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 -- cgit v1.2.3