[recovery_netstack] Replace &mut [u8] with AsMut<[u8]>
- Replace &mut [u8] with AsMut<[u8]> or ByteSliceMut
Test: Existing unit tests
Change-Id: Id840699ea404194f2171b69c256027be1f156626
diff --git a/bin/recovery_netstack/src/wire/arp.rs b/bin/recovery_netstack/src/wire/arp.rs
index 59641c3..f03eed8 100644
--- a/bin/recovery_netstack/src/wire/arp.rs
+++ b/bin/recovery_netstack/src/wire/arp.rs
@@ -17,7 +17,6 @@
use device::ethernet::{EtherType, Mac};
use error::ParseError;
use ip::Ipv4Addr;
-use wire::util::BufferAndRange;
// Header has the same memory layout (thanks to repr(C, packed)) as an ARP
// header. Thus, we can simply reinterpret the bytes of the ARP header as a
@@ -280,8 +279,9 @@
}
}
-impl<'a, HwAddr, ProtoAddr> ArpPacket<&'a mut [u8], HwAddr, ProtoAddr>
+impl<B, HwAddr, ProtoAddr> ArpPacket<B, HwAddr, ProtoAddr>
where
+ B: AsMut<[u8]>,
HwAddr: Copy + HType + FromBytes + AsBytes + Unaligned,
ProtoAddr: Copy + PType + FromBytes + AsBytes + Unaligned,
{
@@ -314,7 +314,7 @@
/// `serialize` panics if there is insufficient room in the buffer to store
/// the ARP packet. The caller can guarantee that there will be enough room
/// by providing a buffer of at least `ArpPacket::MAX_LEN` bytes.
- pub fn serialize<B: AsRef<[u8]> + AsMut<[u8]>>(
+ pub fn serialize(
mut buffer: B, operation: ArpOp, sender_hardware_addr: HwAddr,
sender_protocol_addr: ProtoAddr, target_hardware_addr: HwAddr,
target_protocol_addr: ProtoAddr,
@@ -429,7 +429,7 @@
fn test_serialize() {
let mut buf = [0; 28];
{
- let buffer = ArpPacket::serialize(
+ ArpPacket::serialize(
&mut buf[..],
ArpOp::Request,
TEST_SENDER_MAC,
diff --git a/bin/recovery_netstack/src/wire/ethernet.rs b/bin/recovery_netstack/src/wire/ethernet.rs
index 1cb5e8b..b536884 100644
--- a/bin/recovery_netstack/src/wire/ethernet.rs
+++ b/bin/recovery_netstack/src/wire/ethernet.rs
@@ -187,7 +187,10 @@
}
}
-impl<'a> EthernetFrame<&'a mut [u8]> {
+impl<B> EthernetFrame<B>
+where
+ B: AsMut<[u8]>,
+{
/// Serialize an Ethernet frame in an existing buffer.
///
/// `serialize` serializes an `EthernetFrame` which uses the provided
@@ -227,8 +230,8 @@
/// header, ARP header, etc). See the `DETAILS.md` file in the repository
/// root for more details.
pub fn serialize(
- mut buffer: BufferAndRange<&'a mut [u8]>, src_mac: Mac, dst_mac: Mac, ethertype: EtherType,
- ) -> BufferAndRange<&'a mut [u8]> {
+ mut buffer: BufferAndRange<B>, src_mac: Mac, dst_mac: Mac, ethertype: EtherType,
+ ) -> BufferAndRange<B> {
// NOTE: EtherType values of 1500 and below are used to indicate the
// length of the body in bytes. We don't need to validate this because
// the EtherType enum has no variants with values in that range.
@@ -415,7 +418,7 @@
// create with a body which is below the minimum length
let mut buf = [0u8; 60];
EthernetFrame::serialize(
- BufferAndRange::new(&mut buf, (60 - (MIN_BODY_LEN - 1))..),
+ BufferAndRange::new(&mut buf[..], (60 - (MIN_BODY_LEN - 1))..),
Mac::new([0, 1, 2, 3, 4, 5]),
Mac::new([6, 7, 8, 9, 10, 11]),
EtherType::Arp,
diff --git a/bin/recovery_netstack/src/wire/ipv4.rs b/bin/recovery_netstack/src/wire/ipv4.rs
index ca944aa..2ae4139 100644
--- a/bin/recovery_netstack/src/wire/ipv4.rs
+++ b/bin/recovery_netstack/src/wire/ipv4.rs
@@ -9,7 +9,7 @@
use std::ops::Range;
use byteorder::{ByteOrder, NetworkEndian};
-use zerocopy::{AsBytes, ByteSlice, FromBytes, LayoutVerified, Unaligned};
+use zerocopy::{AsBytes, ByteSlice, ByteSliceMut, FromBytes, LayoutVerified, Unaligned};
use error::ParseError;
use ip::{IpProto, Ipv4Addr, Ipv4Option};
@@ -224,7 +224,10 @@
}
}
-impl<'a> Ipv4Packet<&'a mut [u8]> {
+impl<B> Ipv4Packet<B>
+where
+ B: ByteSliceMut,
+{
/// Set the Time To Live (TTL).
///
/// Set the TTL and update the header checksum accordingly.
diff --git a/bin/recovery_netstack/src/wire/udp.rs b/bin/recovery_netstack/src/wire/udp.rs
index 1fbe208..4f9545f 100644
--- a/bin/recovery_netstack/src/wire/udp.rs
+++ b/bin/recovery_netstack/src/wire/udp.rs
@@ -236,7 +236,10 @@
// in UdpPacket::parse, provides the invariant that a UdpPacket always has a
// valid checksum.
-impl<'a> UdpPacket<&'a mut [u8]> {
+impl<B> UdpPacket<B>
+where
+ B: AsMut<[u8]>,
+{
/// Serialize a UDP packet in an existing buffer.
///
/// `serialize` creates a `UdpPacket` which uses the provided `buffer` for
@@ -267,7 +270,7 @@
/// `serialize` panics if there is insufficient room preceding the body to
/// store the UDP header. The caller can guarantee that there will be enough
/// room by providing at least `MAX_HEADER_LEN` pre-body bytes.
- pub fn serialize<B: AsMut<[u8]>, A: IpAddr>(
+ pub fn serialize<A: IpAddr>(
mut buffer: BufferAndRange<B>, src_ip: A, dst_ip: A, src_port: Option<NonZeroU16>,
dst_port: NonZeroU16,
) -> BufferAndRange<B> {