rust: block: remove RawWriter

`RawWriter` is now dead code, so remove it.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
Link: https://lore.kernel.org/r/20250902-rnull-up-v6-16-v7-9-b5212cc89b98@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Andreas Hindborg 2025-09-02 11:55:03 +02:00 committed by Jens Axboe
parent c3a54220b5
commit f52689fcd8
2 changed files with 0 additions and 57 deletions

View File

@ -89,7 +89,6 @@
pub mod gen_disk;
mod operations;
mod raw_writer;
mod request;
mod tag_set;

View File

@ -1,56 +0,0 @@
// SPDX-License-Identifier: GPL-2.0
use core::fmt::{self, Write};
use crate::error::Result;
use crate::prelude::EINVAL;
/// A mutable reference to a byte buffer where a string can be written into.
///
/// # Invariants
///
/// `buffer` is always null terminated.
pub(crate) struct RawWriter<'a> {
buffer: &'a mut [u8],
pos: usize,
}
impl<'a> RawWriter<'a> {
/// Create a new `RawWriter` instance.
fn new(buffer: &'a mut [u8]) -> Result<RawWriter<'a>> {
*(buffer.last_mut().ok_or(EINVAL)?) = 0;
// INVARIANT: We null terminated the buffer above.
Ok(Self { buffer, pos: 0 })
}
#[expect(dead_code)]
pub(crate) fn from_array<const N: usize>(
a: &'a mut [crate::ffi::c_char; N],
) -> Result<RawWriter<'a>> {
Self::new(
// SAFETY: the buffer of `a` is valid for read and write as `u8` for
// at least `N` bytes.
unsafe { core::slice::from_raw_parts_mut(a.as_mut_ptr().cast::<u8>(), N) },
)
}
}
impl Write for RawWriter<'_> {
fn write_str(&mut self, s: &str) -> fmt::Result {
let bytes = s.as_bytes();
let len = bytes.len();
// We do not want to overwrite our null terminator
if self.pos + len > self.buffer.len() - 1 {
return Err(fmt::Error);
}
// INVARIANT: We are not overwriting the last byte
self.buffer[self.pos..self.pos + len].copy_from_slice(bytes);
self.pos += len;
Ok(())
}
}