Skip to content

Add example of implementing Allocator to its docs - #165287

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
whiplashvin:allocator-trait-example
Nov 2, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
whiplashvin:allocator-trait-example

Conversation

@whiplashvin

Copy link
Copy Markdown
Contributor

Part of #163232

Adds an example In Allocator trait showing a custom allocator with live counts, forwards it to System and is used with
Box::new_in().

r? @tgross35

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 1, 2026
@rustbot

rustbot commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

tgross35 is currently at their maximum review capacity.
They may take a while to respond.

@workingjubilee

workingjubilee commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

System is Send + Sync whereas Cell<T> is only Send. Various types use allocators so the Send + Syncness may or may not matter in a given use-case, but it would seem more useful to suggest a static AtomicUsize, as this will be more like what people will want to do, thus sidestep the Sync gotcha, and not require making the Vec bigger.

@whiplashvin

Copy link
Copy Markdown
Contributor Author

System is Send + Sync whereas Cell<T> is only Send. Various types use allocators so the Send + Syncness may or may not matter in a given use-case, but it would seem more useful to suggest a static AtomicUsize, as this will be more like what people will want to do, thus sidestep the Sync gotcha, and not require making the Vec bigger.

Fixed.

@tgross35 tgross35 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me after these requests

cc @nia-e

View changes since this review

Comment thread library/core/src/alloc/mod.rs Resolved
Comment thread library/core/src/alloc/mod.rs Resolved
Comment thread library/core/src/alloc/mod.rs Resolved
Comment thread library/core/src/alloc/mod.rs Resolved

@tgross35 tgross35 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more request and please squash

View changes since this review

Comment thread library/core/src/alloc/mod.rs Resolved
@whiplashvin
whiplashvin force-pushed the allocator-trait-example branch from c8d975a to 7034526 Compare November 2, 2026 10:07

@tgross35 tgross35 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@bors r+ rollup

View changes since this review

@rust-bors

rust-bors Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 7034526 has been tentatively approved by tgross35

It will be put into the queue for this repository once PR CI succeeds.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 2, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Nov 2, 2026
…e, r=tgross35

Add example of implementing Allocator to its docs

Part of [rust-lang#163232](rust-lang#163232)

Adds an example In Allocator trait showing a custom allocator with live counts, forwards it to `System` and is used with
`Box::new_in()`.

r? @tgross35
rust-bors Bot pushed a commit that referenced this pull request Nov 2, 2026
Rollup of 15 pull requests

Successful merges:

 - #165271 (Re-enable most of `test-aarch64-apple-macos-26-2`)
 - #165331 (miri subtree update)
 - #165211 (Streamline function_item_references lint)
 - #165273 (Add some docs for our allocator `unstable_feature_bound`s)
 - #165279 (explicitly test the win32 symbol byte count suffix)
 - #162688 (Fix invalid suggestions and misleading notes for imports)
 - #165198 (expand the docs of `Complex<T>`)
 - #165231 (Remove redundant parameter from `AttributeParser::parse_attribute_list()` & `AttributeParser::parse_single_args()`)
 - #165248 (add {Receiver,Sender,SyncSender}::{is_empty,len})
 - #165284 (Ensure the display impl of uXX is small with optimize_for_size)
 - #165287 (Add example of implementing Allocator to its docs)
 - #165297 (Cleanup `rustdoc-html` tests)
 - #165298 (Improve diagnostics for notable-trait color arguments)
 - #165336 (Refactor `analyze_attr` to use a match)
 - #165338 (`rust-analyzer` subtree update)
rust-bors Bot pushed a commit that referenced this pull request Nov 2, 2026
Rollup of 15 pull requests

Successful merges:

 - #165271 (Re-enable most of `test-aarch64-apple-macos-26-2`)
 - #165331 (miri subtree update)
 - #165211 (Streamline function_item_references lint)
 - #165273 (Add some docs for our allocator `unstable_feature_bound`s)
 - #165279 (explicitly test the win32 symbol byte count suffix)
 - #162688 (Fix invalid suggestions and misleading notes for imports)
 - #165198 (expand the docs of `Complex<T>`)
 - #165231 (Remove redundant parameter from `AttributeParser::parse_attribute_list()` & `AttributeParser::parse_single_args()`)
 - #165248 (add {Receiver,Sender,SyncSender}::{is_empty,len})
 - #165284 (Ensure the display impl of uXX is small with optimize_for_size)
 - #165287 (Add example of implementing Allocator to its docs)
 - #165297 (Cleanup `rustdoc-html` tests)
 - #165298 (Improve diagnostics for notable-trait color arguments)
 - #165336 (Refactor `analyze_attr` to use a match)
 - #165338 (`rust-analyzer` subtree update)
rust-bors Bot pushed a commit that referenced this pull request Nov 2, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - #165271 (Re-enable most of `test-aarch64-apple-macos-26-2`)
 - #165211 (Streamline function_item_references lint)
 - #165273 (Add some docs for our allocator `unstable_feature_bound`s)
 - #165279 (explicitly test the win32 symbol byte count suffix)
 - #162688 (Fix invalid suggestions and misleading notes for imports)
 - #165198 (expand the docs of `Complex<T>`)
 - #165231 (Remove redundant parameter from `AttributeParser::parse_attribute_list()` & `AttributeParser::parse_single_args()`)
 - #165248 (add {Receiver,Sender,SyncSender}::{is_empty,len})
 - #165284 (Ensure the display impl of uXX is small with optimize_for_size)
 - #165287 (Add example of implementing Allocator to its docs)
 - #165297 (Cleanup `rustdoc-html` tests)
 - #165298 (Improve diagnostics for notable-trait color arguments)
 - #165336 (Refactor `analyze_attr` to use a match)
 - #165338 (`rust-analyzer` subtree update)
@rust-bors
rust-bors Bot merged commit b6cc355 into rust-lang:main Nov 2, 2026
14 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Nov 2, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 2, 2026
Rollup merge of #165287 - whiplashvin:allocator-trait-example, r=tgross35

Add example of implementing Allocator to its docs

Part of [#163232](#163232)

Adds an example In Allocator trait showing a custom allocator with live counts, forwards it to `System` and is used with
`Box::new_in()`.

r? @tgross35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants