Skip to content

Commit

Permalink
Remove mention of Box::default.
Browse files Browse the repository at this point in the history
It is no longer treated specially. See #80 for details.
  • Loading branch information
nnethercote committed Apr 16, 2024
1 parent b095cbc commit 2e7a0b9
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions src/standard-library-types.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Standard Library Types

It is worth reading through the documentation for common standard library
types—such as [`Box`], [`Vec`], [`Option`], [`Result`], and [`Rc`]/[`Arc`]—to find interesting
types—such as [`Vec`], [`Option`], [`Result`], and [`Rc`]/[`Arc`]—to find interesting
functions that can sometimes be used to improve performance.

[`Box`]: https://doc.rust-lang.org/std/boxed/struct.Box.html
[`Vec`]: https://doc.rust-lang.org/std/vec/struct.Vec.html
[`Option`]: https://doc.rust-lang.org/std/option/enum.Option.html
[`Result`]: https://doc.rust-lang.org/std/result/enum.Result.html
Expand All @@ -20,16 +19,6 @@ library types, such as [`Mutex`], [`RwLock`], [`Condvar`], and
[`Condvar`]: https://doc.rust-lang.org/std/sync/struct.Condvar.html
[`Once`]: https://doc.rust-lang.org/std/sync/struct.Once.html

## `Box`

The expression [`Box::default()`] has the same effect as
`Box::new(T::default())` but can be faster because the compiler can create the
value directly on the heap, rather than constructing it on the stack and then
copying it over.
[**Example**](https://github.com/komora-io/art/commit/d5dc58338f475709c375e15976d0d77eb5d7f7ef).

[`Box::default()`]: https://doc.rust-lang.org/std/boxed/struct.Box.html#method.default

## `Vec`

The best way to create a zero-filled `Vec` of length `n` is with `vec![0; n]`.
Expand Down

0 comments on commit 2e7a0b9

Please sign in to comment.