Skip to content

Add Mutex::arc method #74866

Closed
Closed
@MarinPostma

Description

@MarinPostma

Mutexes are seldom used without an Arc, I propose to add a method Mutex::arc that returns an Arc<Mutex<_>>. This would make code more readable and compact almost everywhere mutexes are used. It also makes the intent clearer, as we first think about the Mutex, not the Arc when we use one.

// this:
let mutex = Arc::new(Mutex::new(Thing { inner: 0 }));
// would turn into this
let mutex = Mutex::arc(Thing { inner: 0 });

This would also mimic what we already have with the Box::pin method that return a Pin<Box<_>>.

Metadata

Metadata

Assignees

Labels

C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions