Skip to content

Receive &Ptr instead of Ptr in PtrValueIter::new#119

Merged
nunoplopes merged 2 commits into
Cpp2Rust:masterfrom
lucic71:ptr-value-iter
May 18, 2026
Merged

Receive &Ptr instead of Ptr in PtrValueIter::new#119
nunoplopes merged 2 commits into
Cpp2Rust:masterfrom
lucic71:ptr-value-iter

Conversation

@lucic71
Copy link
Copy Markdown
Contributor

@lucic71 lucic71 commented May 18, 2026

let start: Value<Ptr<u8>> = ...;
PtrValueIter::new((*start.borrow()), __count).collect::<Vec<_>>()

tries to move out of (*start.borrow()) which does not implement the Copy trait because Ptr does not implement Copy.

To avoid the move, change the ptr argument of PtrValueIter::new to &Ptr<T> instead of Ptr<T>

pub fn new(ptr: &Ptr<T>, n: usize) -> Self 
                ^

This pattern is not new, it's also used in Ptr::memcpy, Ptr::memset, Ptr::slice_until.

@nunoplopes nunoplopes merged commit f560745 into Cpp2Rust:master May 18, 2026
9 checks passed
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.

2 participants