Implementing Clone for the Insn and cs_insn Structures #165
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Typically, when writing more complex code using
capstone
we can collectcs_insn
structures on their own.For example, we can create a list of
cs_insn
structures in Python without them going out of scope.Currently this is not appearing to be possible in
capstone-rs
because theInsn
andcs_insn
structures only being accessed by reference when contained inInstructions
iterator.Most of the work on implementing the
clone
functionality has already been done forcs_detail
structure and others.This PR simply implements
clone
for bothcs_insn
andInsn
structures, so it is possible to store these for later use in more complex projects.Here is an example of using this functionality:
It also helps for when we need to iterate a single instruction at a time collecting them for later post-processing.
This becomes an issue when having to unpack from the
Instructions
iterator and only getting references without the possibility of cloning for later use.This should not break any other features, it simply continues what was already done with
cs_detail
and other placesclone
has already been implemented in thecapstone-rs
project.That being said, this is my first Rust-based PR, so proceed with caution.
Thank you 😄