I saw this code:
ip_repr.emit(frame.payload_mut(), &caps.checksum);
let payload = &mut frame.payload_mut()[ip_repr.buffer_len()..];
packet.emit_payload(ip_repr, payload, &caps);
and I'm trying to do the same but for tx_buffer: &mut [u8]
as you see below:
ip_repr.emit(tx_buffer, &caps.checksum);
let payload = &mut tx_buffer[ip_repr.buffer_len()..];
packet.emit_payload(ip_repr, payload, &caps);
but I get an error on the let payload =
line:
borrow of moved value: `tx_buffer`
value borrowed here after moverustc(E0382)
Since tx_buffer
is a mutable reference, then on the emit
call, emit
borrows it, not move. So I should be able to use it in the second line, borrowing it again. Also, how can it work for frame.payload_mut()
without errors, since it's also passed 2 times?
signatures:
pub fn payload_mut(&mut self) -> &mut [u8]
pub fn emit<T: AsRef<[u8]> + AsMut<[u8]>>(
&self,
buffer: T,
_checksum_caps: &ChecksumCapabilities,
)
pub fn emit_payload(&self, _ip_repr: IpRepr, payload: &mut [u8], caps: &DeviceCapabilities)