• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Copy slice into its own array

Resolved: Copy slice into its own array

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I want to copy the values at one slice of an array into another slice.
The obvious way (using iteration) is:
However, that seems rather inefficient.
The usual way to copy a slice:
does not work as arr is borrowed twice.
The only other way to do this that comes to mind is std::ptr::copy_nonoverlapping, which is unsafe.
What is the best way to copy a slice into its own array (while knowing that source and destination do not overlap)?

Answer:

Using copy_within():
Note that it does not require them to not overlap.
If you’re sure they do not overlap, and you want to exploit that, you can use unsafe code:

If you have better answer, please add a comment about this, thank you!

arrays borrow-checker memcpy rust slice
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: net::ERR_HTTP2_PROTOCOL_ERROR by http get request angular 15.2

02/04/2023

Resolved: How do I stop the command from happening if the requirements for it to work aren’t sert Discord.js

02/04/2023

Resolved: How to scroll bottom of div at launch?

02/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.