X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=src%2Fslip.rs;h=6bb508bf2cfe25894aa00dcc3f27c5dfcaa4472d;hb=8e21ba311cb9fa2e9c700897b429c04e0f80749c;hp=955c36f624dddd027e0798fe2e7c04947af1d480;hpb=0d1c6a752c831816de8850927dc9a521a7e8bcee;p=hippotat.git diff --git a/src/slip.rs b/src/slip.rs index 955c36f..6bb508b 100644 --- a/src/slip.rs +++ b/src/slip.rs @@ -24,13 +24,14 @@ impl SlipMime for Slip2Mime { const CONV_TO: Option = Some(true); } impl SlipMime for Mime2Slip { const CONV_TO: Option = Some(false); } impl SlipMime for SlipNoConv { const CONV_TO: Option = None; } -#[derive(Debug)] -#[derive(Error)] -#[error("only bad IP datagrams")] -pub struct ErrorOnlyBad; - -#[throws(ErrorOnlyBad)] -pub fn checkn( +#[derive(Debug,Error)] +pub enum SlipFramesError where E: std::error::Error + 'static { + #[error("only bad IP datagrams")] ErrorOnlyBad, + #[error("{0}")] Other(#[from] E), +} + +#[throws(SlipFramesError)] +pub fn checkn( mime: M, mtu: u32, data: &[u8], @@ -39,7 +40,8 @@ pub fn checkn( mut error_handler: EH ) where AC: Fn(&[u8]) -> Result + Copy, OUT: FnMut((Box<[u8]>, ACR)) -> Result<(), PacketError>, - EH: FnMut(PacketError), + EH: FnMut(PacketError) -> Result<(), SlipFramesError>, + EHE: std::error::Error + 'static, { // eprintln!("before: {:?}", DumpHex(data)); if data.is_empty() { return } @@ -54,11 +56,11 @@ pub fn checkn( Ok::<_,PE>(()) })() { Ok(()) => { }, - Err(e) => { err=true; error_handler(e); }, + Err(e) => { err=true; error_handler(e)?; }, } } // eprintln!(" after: {:?}", DumpHex(data)); - if err && !ok { throw!(ErrorOnlyBad) } + if err && !ok { throw!(SlipFramesError::ErrorOnlyBad) } } #[throws(PacketError)]