From 27514d58573ce1f844af4ea60afa72c7f58f1cd7 Mon Sep 17 00:00:00 2001 From: Jasper Ras Date: Thu, 21 Aug 2025 22:09:29 +0200 Subject: vault backup: 2025-08-21 22:09:29 --- Rust Ownership.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Rust Ownership.md (limited to 'Rust Ownership.md') diff --git a/Rust Ownership.md b/Rust Ownership.md new file mode 100644 index 0000000..7d8c97e --- /dev/null +++ b/Rust Ownership.md @@ -0,0 +1,24 @@ +[[Ownership]] +[[Lifetime]] + + +[[Undefined behaviour is caught by the compiler]] +[[Variables lives on the stack]] +[[To put data on the heap use a Box]] +[[Cloning a box does a deep copy of the heap data]] +[[Aliasing just means that multiple variables point to the same heap data]] +[[A place is anything that is valid to put on the left-hand side of an assignment]] + +[[Dereferencing is to access the data behind a pointer]] +[[Aliasing just means that multiple variables point to the same heap data]] +[[Variables are subject to permissions similar to files on linux]] +[[References temporarily remove permissions]] +[[Creating a reference to a variable is called borrowing]] +[[It is illegal to create a mutable reference while an immutable reference is live]] +[[Data must outlive any references to it]] +[[Move ownership out of the function]] +[[Return a static literal]] +[[Defer borrow checking to runtime with garbage collection]] +[[Provide a slot by the caller]] +[[Clone a reference in a function to modify it]] +[[Shortening the lifetime of borrowed variables before mutating it]] -- cgit v1.2.3