aboutsummaryrefslogtreecommitdiff
path: root/embassy-net-ppp/src/lib.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-08-25 16:04:22 +0200
committerDario Nieuwenhuis <[email protected]>2023-08-25 20:45:23 +0200
commita026db3f570cae504dc5da6c7055afc52e122930 (patch)
treeee40df333013448f04ec1537518e604fc8929b77 /embassy-net-ppp/src/lib.rs
parentc2d601abeff6f9f911b8140f3ceb6806971dc7dd (diff)
net-ppp: use From and ? to handle write errors.
Diffstat (limited to 'embassy-net-ppp/src/lib.rs')
-rw-r--r--embassy-net-ppp/src/lib.rs21
1 files changed, 11 insertions, 10 deletions
diff --git a/embassy-net-ppp/src/lib.rs b/embassy-net-ppp/src/lib.rs
index df583fb37..e3b208ee6 100644
--- a/embassy-net-ppp/src/lib.rs
+++ b/embassy-net-ppp/src/lib.rs
@@ -55,6 +55,15 @@ pub enum RunError<E> {
55 Eof, 55 Eof,
56} 56}
57 57
58impl<E> From<WriteAllError<E>> for RunError<E> {
59 fn from(value: WriteAllError<E>) -> Self {
60 match value {
61 WriteAllError::Other(e) => Self::Write(e),
62 WriteAllError::WriteZero => Self::WriteZero,
63 }
64 }
65}
66
58impl<'d> Runner<'d> { 67impl<'d> Runner<'d> {
59 /// You must call this in a background task for the driver to operate. 68 /// You must call this in a background task for the driver to operate.
60 /// 69 ///
@@ -112,11 +121,7 @@ impl<'d> Runner<'d> {
112 buf[..pkt.len()].copy_from_slice(pkt); 121 buf[..pkt.len()].copy_from_slice(pkt);
113 rx_chan.rx_done(pkt.len()); 122 rx_chan.rx_done(pkt.len());
114 } 123 }
115 PPPoSAction::Transmit(n) => match rw.write_all(&tx_buf[..n]).await { 124 PPPoSAction::Transmit(n) => rw.write_all(&tx_buf[..n]).await?,
116 Ok(()) => {}
117 Err(WriteAllError::WriteZero) => return Err(RunError::WriteZero),
118 Err(WriteAllError::Other(e)) => return Err(RunError::Write(e)),
119 },
120 } 125 }
121 126
122 match ppp.status().phase { 127 match ppp.status().phase {
@@ -126,11 +131,7 @@ impl<'d> Runner<'d> {
126 } 131 }
127 Either::Second(pkt) => { 132 Either::Second(pkt) => {
128 match ppp.send(pkt, &mut tx_buf) { 133 match ppp.send(pkt, &mut tx_buf) {
129 Ok(n) => match rw.write_all(&tx_buf[..n]).await { 134 Ok(n) => rw.write_all(&tx_buf[..n]).await?,
130 Ok(()) => {}
131 Err(WriteAllError::WriteZero) => return Err(RunError::WriteZero),
132 Err(WriteAllError::Other(e)) => return Err(RunError::Write(e)),
133 },
134 Err(BufferFullError) => unreachable!(), 135 Err(BufferFullError) => unreachable!(),
135 } 136 }
136 tx_chan.tx_done(); 137 tx_chan.tx_done();