From 6ca3ac0d9ca97ffb62db2d732f1663cb22da2c26 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 7 Jul 2021 22:41:34 +0200 Subject: rust: Add notes Signed-off-by: Matthias Beyer --- .../programming/programming_languages/rust.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'content') 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::>(); +``` + +It does still panic, though, because the element counter overflows. + +--- -- cgit v1.2.3