Skip to content

Add Vec::push_mut#670

Open
mdrssv wants to merge 1 commit into
rust-embedded:mainfrom
mdrssv:push-mut
Open

Add Vec::push_mut#670
mdrssv wants to merge 1 commit into
rust-embedded:mainfrom
mdrssv:push-mut

Conversation

@mdrssv

@mdrssv mdrssv commented Jul 16, 2026

Copy link
Copy Markdown

Mirrors: std::vec::Vec::push_mut into heapless

@sgued sgued left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the contribution! This looks useful.

Some of the clippy lints failure are caused by existing code and the update to 1.97 and will be fixed in #671, but there are still a couple of them that are in your code.

Comment thread src/vec/mod.rs Outdated
Comment thread src/vec/mod.rs Outdated

@sgued sgued left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the contribution! This looks useful.

Some of the clippy lints failure are caused by existing code and the update to 1.97 and have been fixed in #671 so please rebase on top of master. There are still a couple of lints that affect your code though.

@zeenix zeenix left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I left a comment with 2 changes requested.

@mdrssv
mdrssv force-pushed the push-mut branch 2 times, most recently from 73480ce to f08dcc5 Compare July 16, 2026 11:56
@mdrssv

mdrssv commented Jul 16, 2026

Copy link
Copy Markdown
Author

Thanks for the feedback

@mdrssv
mdrssv force-pushed the push-mut branch 2 times, most recently from 75fdb90 to 0ff8b28 Compare July 16, 2026 12:00
Comment thread src/vec/mod.rs Outdated
@mdrssv
mdrssv force-pushed the push-mut branch 2 times, most recently from 3a68dfb to 357cde6 Compare July 17, 2026 10:12
Comment thread src/vec/mod.rs
Comment on lines +703 to +706
// Safety: len has been checked to be less then capacity, enough for one more item
unsafe { self.push_unchecked(item) };
// Safety: len which was obtained before insertion now corresponds to self.len() - 1
// representing the index for the just added item

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comments here are still missing their .. :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A final thouch and we can merge it, thanks!

Comment thread src/vec/mod.rs
pub fn push_mut(&mut self, item: T) -> Result<&mut T, T> {
let len = self.len();
if len < self.capacity() {
// Safety: len has been checked to be less then capacity, enough for one more item

@sgued sgued Jul 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A little typo

Suggested change
// Safety: len has been checked to be less then capacity, enough for one more item
// Safety: len has been checked to be less than capacity, enough for one more item

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants