summaryrefslogtreecommitdiff
path: root/Creating a reference to a variable is called borrowing.md
diff options
context:
space:
mode:
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