summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-07-07 22:41:34 +0200
committerMatthias Beyer <mail@beyermatthias.de>2021-07-07 22:41:34 +0200
commit6ca3ac0d9ca97ffb62db2d732f1663cb22da2c26 (patch)
tree6551f4e6bf02ff97fa86c4afa705838320d3e954 /content
parente263266e08b4062e3b4b80e174b8818b97ed7bb4 (diff)
rust: Add notes
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'content')
-rw-r--r--content/computer/programming/programming_languages/rust.md19
1 files changed, 19 insertions, 0 deletions
diff --git a/content/computer/programming/programming_languages/rust.md b/content/computer/programming/programming_languages/rust.md
index d7d5c01..b0032bc 100644
--- a/content/computer/programming/programming_languages/rust.md
+++ b/content/computer/programming/programming_languages/rust.md
@@ -37,3 +37,22 @@ weight = 1
* [clap](https://clap.rs) - State of the art commandline interface building and parsing
+
+# Notes
+
+---
+
+The Rust standard library actually optimizes zero-size-type allocations away,
+for example
+[here](https://github.com/rust-lang/rust/blob/866335b337964c79372cd6b1b1213f168efd311f/library/alloc/src/raw_vec.rs#L188),
+allocations are prevented if the generic type `T` is zero sized.
+
+Thus, the following code will never allocate after the first allocation:
+
+```rust
+let _ = std::iter::repeat(()).collect::<Vec<()>>();
+```
+
+It does still panic, though, because the element counter overflows.
+
+---