mirror of
https://github.com/smoltcp-rs/smoltcp.git
synced 2025-10-02 15:15:05 +00:00
Change mutability of RxToken
's consume
argument.
This drops the requirement that we can mutate the receive buffer, which is not always te case.
This commit is contained in:
parent
125773e282
commit
4055a19bc3
@ -274,7 +274,7 @@ pub struct RxToken<'a> {
|
|||||||
impl<'a> phy::RxToken for RxToken<'a> {
|
impl<'a> phy::RxToken for RxToken<'a> {
|
||||||
fn consume<R, F>(self, f: F) -> R
|
fn consume<R, F>(self, f: F) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut [u8]) -> R,
|
F: FnOnce(&[u8]) -> R,
|
||||||
{
|
{
|
||||||
f(self.buf)
|
f(self.buf)
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
extern crate alloc;
|
||||||
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
use crate::phy::{self, Device, DeviceCapabilities};
|
use crate::phy::{self, Device, DeviceCapabilities};
|
||||||
use crate::time::Instant;
|
use crate::time::Instant;
|
||||||
|
|
||||||
@ -92,11 +95,12 @@ pub struct RxToken<'a, Rx: phy::RxToken, F: Fuzzer + 'a> {
|
|||||||
impl<'a, Rx: phy::RxToken, FRx: Fuzzer> phy::RxToken for RxToken<'a, Rx, FRx> {
|
impl<'a, Rx: phy::RxToken, FRx: Fuzzer> phy::RxToken for RxToken<'a, Rx, FRx> {
|
||||||
fn consume<R, F>(self, f: F) -> R
|
fn consume<R, F>(self, f: F) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut [u8]) -> R,
|
F: FnOnce(&[u8]) -> R,
|
||||||
{
|
{
|
||||||
self.token.consume(|buffer| {
|
self.token.consume(|buffer| {
|
||||||
self.fuzzer.fuzz_packet(buffer);
|
let mut new_buffer: Vec<u8> = buffer.to_vec();
|
||||||
f(buffer)
|
self.fuzzer.fuzz_packet(&mut new_buffer);
|
||||||
|
f(&mut new_buffer)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,11 +61,11 @@ pub struct RxToken {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl phy::RxToken for RxToken {
|
impl phy::RxToken for RxToken {
|
||||||
fn consume<R, F>(mut self, f: F) -> R
|
fn consume<R, F>(self, f: F) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut [u8]) -> R,
|
F: FnOnce(&[u8]) -> R,
|
||||||
{
|
{
|
||||||
f(&mut self.buffer)
|
f(&self.buffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,11 +62,11 @@ impl phy::Device for StmPhy {
|
|||||||
struct StmPhyRxToken<'a>(&'a mut [u8]);
|
struct StmPhyRxToken<'a>(&'a mut [u8]);
|
||||||
|
|
||||||
impl<'a> phy::RxToken for StmPhyRxToken<'a> {
|
impl<'a> phy::RxToken for StmPhyRxToken<'a> {
|
||||||
fn consume<R, F>(mut self, f: F) -> R
|
fn consume<R, F>(self, f: F) -> R
|
||||||
where F: FnOnce(&mut [u8]) -> R
|
where F: FnOnce(& [u8]) -> R
|
||||||
{
|
{
|
||||||
// TODO: receive packet into buffer
|
// TODO: receive packet into buffer
|
||||||
let result = f(&mut self.0);
|
let result = f(&self.0);
|
||||||
println!("rx called");
|
println!("rx called");
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
@ -372,7 +372,7 @@ pub trait RxToken {
|
|||||||
/// packet bytes as argument.
|
/// packet bytes as argument.
|
||||||
fn consume<R, F>(self, f: F) -> R
|
fn consume<R, F>(self, f: F) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut [u8]) -> R;
|
F: FnOnce(&[u8]) -> R;
|
||||||
|
|
||||||
/// The Packet ID associated with the frame received by this [`RxToken`]
|
/// The Packet ID associated with the frame received by this [`RxToken`]
|
||||||
fn meta(&self) -> PacketMeta {
|
fn meta(&self) -> PacketMeta {
|
||||||
|
@ -219,7 +219,7 @@ pub struct RxToken<'a, Rx: phy::RxToken, S: PcapSink> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Rx: phy::RxToken, S: PcapSink> phy::RxToken for RxToken<'a, Rx, S> {
|
impl<'a, Rx: phy::RxToken, S: PcapSink> phy::RxToken for RxToken<'a, Rx, S> {
|
||||||
fn consume<R, F: FnOnce(&mut [u8]) -> R>(self, f: F) -> R {
|
fn consume<R, F: FnOnce(&[u8]) -> R>(self, f: F) -> R {
|
||||||
self.token.consume(|buffer| {
|
self.token.consume(|buffer| {
|
||||||
match self.mode {
|
match self.mode {
|
||||||
PcapMode::Both | PcapMode::RxOnly => self
|
PcapMode::Both | PcapMode::RxOnly => self
|
||||||
|
@ -104,11 +104,11 @@ pub struct RxToken {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl phy::RxToken for RxToken {
|
impl phy::RxToken for RxToken {
|
||||||
fn consume<R, F>(mut self, f: F) -> R
|
fn consume<R, F>(self, f: F) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut [u8]) -> R,
|
F: FnOnce(&[u8]) -> R,
|
||||||
{
|
{
|
||||||
f(&mut self.buffer[..])
|
f(&self.buffer[..])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ pub struct RxToken<Rx: phy::RxToken> {
|
|||||||
impl<Rx: phy::RxToken> phy::RxToken for RxToken<Rx> {
|
impl<Rx: phy::RxToken> phy::RxToken for RxToken<Rx> {
|
||||||
fn consume<R, F>(self, f: F) -> R
|
fn consume<R, F>(self, f: F) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut [u8]) -> R,
|
F: FnOnce(&[u8]) -> R,
|
||||||
{
|
{
|
||||||
self.token.consume(|buffer| {
|
self.token.consume(|buffer| {
|
||||||
(self.writer)(
|
(self.writer)(
|
||||||
|
@ -93,11 +93,11 @@ pub struct RxToken {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl phy::RxToken for RxToken {
|
impl phy::RxToken for RxToken {
|
||||||
fn consume<R, F>(mut self, f: F) -> R
|
fn consume<R, F>(self, f: F) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut [u8]) -> R,
|
F: FnOnce(&[u8]) -> R,
|
||||||
{
|
{
|
||||||
f(&mut self.buffer[..])
|
f(&self.buffer[..])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,11 +120,11 @@ pub struct RxToken {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl phy::RxToken for RxToken {
|
impl phy::RxToken for RxToken {
|
||||||
fn consume<R, F>(mut self, f: F) -> R
|
fn consume<R, F>(self, f: F) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut [u8]) -> R,
|
F: FnOnce(&[u8]) -> R,
|
||||||
{
|
{
|
||||||
f(&mut self.buffer)
|
f(&self.buffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user