Poperton
Poperton

Reputation: 2226

Why reborrowing &mut[u8] makes its size unknown at compile time?

I'm creating a mutable [u8] buffer as this:

let buffer: &mut [u8] = &mut [0u8; 34];

and using here:

repr.emit(&mut *buffer, &caps.checksum);

and reborrowing here:

assert_eq!(processor!(iface).process_ip_payload(&mut ip, &mut socket_set, Instant::from_millis(0), &mut *buffer), Ok(Some(expected_repr)));

I get:

the size for values of type [u8] cannot be known at compilation time

doesn't have a size known at compile-time

for the ...,&mut *buffer) reborrow (the last one, on assert).

The original buffer has its size known at compile time. Why reborrowing makes the size unknown?

Here are the signatures if needed:

    pub fn emit<T: AsRef<[u8]> + AsMut<[u8]>>(
        &self,
        buffer: T,
        _checksum_caps: &ChecksumCapabilities,
    )
    fn process_ip_payload<'frame, T: AsRef<[u8]>>(
        &mut self,
        ip: &mut ip::Processor,
        sockets: &mut SocketSet,
        timestamp: Instant,
        frame: &'frame T,
    ) -> Result<Option<ip::Packet<'frame>>>

Upvotes: 0

Views: 505

Answers (1)

APerson
APerson

Reputation: 8422

Don't dereference buffer when you pass it in as an argument:

assert_eq!(processor!(iface).process_ip_payload(
    &mut ip, &mut socket_set, Instant::from_millis(0), &mut buffer),
    Ok(Some(expected_repr)));

(&mut buffer instead of &mut *buffer).

Upvotes: 1

Related Questions