pub struct LineTransport<'a> { /* private fields */ }Expand description
Line-oriented packet source for file/stdin style transports.
Implementations§
Source§impl<'a> LineTransport<'a>
impl<'a> LineTransport<'a>
Sourcepub fn new(input: &'a [u8]) -> Self
pub fn new(input: &'a [u8]) -> Self
Creates a transport over newline-separated packet bytes.
Examples found in repository?
examples/process_file.rs (line 12)
3fn main() -> std::io::Result<()> {
4 let Some(path) = std::env::args().nth(1) else {
5 eprintln!("usage: process_file <packets.aprs>");
6 std::process::exit(2);
7 };
8
9 let input = std::fs::read(path)?;
10 let mut engine = Engine::new(Policy::strict());
11
12 for packet_bytes in LineTransport::new(&input).packets() {
13 match engine.process(packet_bytes) {
14 EngineResult::Accepted { packet } => println!("{}", packet.to_json()),
15 EngineResult::Rejected { reason, .. } => eprintln!("rejected: {}", reason.code()),
16 EngineResult::ParseError(error) => eprintln!("malformed: {}", error.code()),
17 }
18 }
19
20 Ok(())
21}Sourcepub fn packets(&self) -> Vec<&'a [u8]>
pub fn packets(&self) -> Vec<&'a [u8]>
Iterates packet lines without trailing CR/LF bytes.
Examples found in repository?
examples/process_file.rs (line 12)
3fn main() -> std::io::Result<()> {
4 let Some(path) = std::env::args().nth(1) else {
5 eprintln!("usage: process_file <packets.aprs>");
6 std::process::exit(2);
7 };
8
9 let input = std::fs::read(path)?;
10 let mut engine = Engine::new(Policy::strict());
11
12 for packet_bytes in LineTransport::new(&input).packets() {
13 match engine.process(packet_bytes) {
14 EngineResult::Accepted { packet } => println!("{}", packet.to_json()),
15 EngineResult::Rejected { reason, .. } => eprintln!("rejected: {}", reason.code()),
16 EngineResult::ParseError(error) => eprintln!("malformed: {}", error.code()),
17 }
18 }
19
20 Ok(())
21}Trait Implementations§
Source§impl<'a> Clone for LineTransport<'a>
impl<'a> Clone for LineTransport<'a>
Source§fn clone(&self) -> LineTransport<'a>
fn clone(&self) -> LineTransport<'a>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<'a> Debug for LineTransport<'a>
impl<'a> Debug for LineTransport<'a>
Source§impl<'a> PartialEq for LineTransport<'a>
impl<'a> PartialEq for LineTransport<'a>
impl<'a> Eq for LineTransport<'a>
impl<'a> StructuralPartialEq for LineTransport<'a>
Auto Trait Implementations§
impl<'a> Freeze for LineTransport<'a>
impl<'a> RefUnwindSafe for LineTransport<'a>
impl<'a> Send for LineTransport<'a>
impl<'a> Sync for LineTransport<'a>
impl<'a> Unpin for LineTransport<'a>
impl<'a> UnsafeUnpin for LineTransport<'a>
impl<'a> UnwindSafe for LineTransport<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more