https://github.com/zpg6/strlinebuf
Simple no_std line buffer for separating lines from a byte stream.
https://github.com/zpg6/strlinebuf
Last synced: 9 months ago
JSON representation
Simple no_std line buffer for separating lines from a byte stream.
- Host: GitHub
- URL: https://github.com/zpg6/strlinebuf
- Owner: zpg6
- License: mit
- Created: 2024-12-15T01:50:04.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-15T02:10:00.000Z (over 1 year ago)
- Last Synced: 2025-02-09T16:36:52.723Z (over 1 year ago)
- Language: Rust
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# strlinebuf
Simple `#![no_std]` line buffer for separating lines from a byte stream. For example, reading from a serial port byte by byte and assembling into lines.
## Basic Usage
```rust
use strlinebuf::LineBuffer;
// Capacity of the buffer is 10 bytes
let mut line_buffer = LineBuffer::<10>::new();
line_buffer.push_bytes(b"Hello\n").unwrap();
let mut aux_buffer = [0u8; 10];
let bytes_read = line_buffer.read_line_bytes(&mut aux_buffer).unwrap();
let line = core::str::from_utf8(&aux_buffer[..bytes_read]).unwrap();
// line == "Hello"
```
## Configuration
You can also configure the terminator character and the capacity of the buffer.
```rust
use strlinebuf::{LineBuffer, LineBufferConfig, Terminator};
let line_buffer = LineBuffer::<24>::new_with_config(LineBufferConfig {
terminator: Terminator::CarriageReturn,
});
```