summaryrefslogtreecommitdiffstats
path: root/rsnix/src/strbuf.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-08-01 18:25:55 +0200
committersalmonik <salmonik@tuta.io>2026-08-01 18:25:55 +0200
commit1ea2f68e6a9af135e6cb3274fdf28d4ddc5812d5 (patch)
treef28246586e387293d0c8beaf6b445210aaab8c48 /rsnix/src/strbuf.rs
parentklog/tty/pager: no more truncated lines — full lines flow, terminal wraps (diff)
downloadrs-dos-1ea2f68e6a9af135e6cb3274fdf28d4ddc5812d5.tar.gz
rs-dos-1ea2f68e6a9af135e6cb3274fdf28d4ddc5812d5.zip
fix pi-lens warnings: unwraps, shell SC2046, dup code (fmtbuf/scripts/hexdump/cat/ahci/pci)
- memory.rs: self-test Layout::from_size_align no longer panics — the test fails cleanly on an invalid layout - fat.rs: v() no longer unwraps the active-volume slot — invariant violation logs + halts instead of panicking mid-disk-io - strbuf: shared FmtBuf replaces the duplicated PanicBuf/FmtBuf (main.rs + sched.rs) - test-disk.sh: SC2046 — conditional --fresh arg no longer relies on word splitting - scripts: boot.sh/boot-image.sh share lib-boot-args.sh (dup args loop) - shell: cat/hexdump stdin pairs unified with Option<&str> marker; hexdump format_row folded into format_partial - ahci: read/write_sectors unified behind dma_sectors - pci: config_read/write share config_addr
Diffstat (limited to '')
-rw-r--r--rsnix/src/strbuf.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/rsnix/src/strbuf.rs b/rsnix/src/strbuf.rs
index 262720d..0e3ea56 100644
--- a/rsnix/src/strbuf.rs
+++ b/rsnix/src/strbuf.rs
@@ -69,3 +69,31 @@ impl<const N: usize> fmt::Debug for String<N> {
69 write!(f, "{:?}", self.as_str()) 69 write!(f, "{:?}", self.as_str())
70 } 70 }
71} 71}
72
73/// Small `fmt::Write` over a byte slice — no allocation, bounded.
74/// Shared by the panic handler (task-panic message) and the scheduler
75/// (page-fault abort message) so they don't each reinvent it.
76pub struct FmtBuf<'a> {
77 b: &'a mut [u8],
78 n: usize,
79}
80
81impl<'a> FmtBuf<'a> {
82 pub fn new(b: &'a mut [u8]) -> Self {
83 FmtBuf { b, n: 0 }
84 }
85
86 /// Bytes written so far (clamped at the buffer length).
87 pub fn len(&self) -> usize {
88 self.n
89 }
90}
91
92impl fmt::Write for FmtBuf<'_> {
93 fn write_str(&mut self, s: &str) -> fmt::Result {
94 let m = s.len().min(self.b.len() - self.n);
95 self.b[self.n..self.n + m].copy_from_slice(&s.as_bytes()[..m]);
96 self.n += m;
97 Ok(())
98 }
99}