summaryrefslogtreecommitdiff
path: root/Creating a reference to a variable is called borrowing.md
diff options
context:
space:
mode:
authorJasper Ras <jras@hostnet.nl>2025-08-05 08:53:21 +0200
committerJasper Ras <jras@hostnet.nl>2025-08-05 08:53:21 +0200
commit295b343aecf330e830d79f06e0efc511e7d76da1 (patch)
tree85057ef1fe401adcd0d958ddf6ff966f25d8fef0 /Creating a reference to a variable is called borrowing.md
parentf43372529e655f3b039946c969e4465193eb2042 (diff)
vault backup: 2025-08-05 08:53:21
Diffstat (limited to 'Creating a reference to a variable is called borrowing.md')
-rw-r--r--Creating a reference to a variable is called borrowing.md13
1 files changed, 13 insertions, 0 deletions
diff --git a/Creating a reference to a variable is called borrowing.md b/Creating a reference to a variable is called borrowing.md
new file mode 100644
index 0000000..245d060
--- /dev/null
+++ b/Creating a reference to a variable is called borrowing.md
@@ -0,0 +1,13 @@
+[[Rust]]
+[[References are also immutable by default]]
+[[Mutable references are safe because they prevent aliasing]]
+[[Ownership]]
+[[Dereferencing is to access the data behind a pointer]]
+
+---
+
+Creating a reference is done with an ampersand. It creates a pointer to another variable in the stack, which could be a pointer to something on the heap.
+
+This is called borrowing.
+
+A reference is a non-owning pointer; so if we create a reference to a Box we can safely have it discarded and continue using the box because the heap data is not deallocated. \ No newline at end of file