Avoid StringWriter cast and string format

This commit is contained in:
Wildan M
2026-05-20 09:10:25 +07:00
parent b07babc03c
commit 4a7f2d80ff
7 changed files with 32 additions and 25 deletions
+2 -2
View File
@@ -147,13 +147,13 @@ impl Read for FileReader {
}
/// An implementation of [`Write`]/[`core::fmt::Write`] for a byte array.
pub struct StringWriter(pub *mut u8, pub usize);
pub struct StringWriter(pub *mut c_char, pub usize);
impl Write for StringWriter {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
if self.1 > 1 {
let copy_size = buf.len().min(self.1 - 1);
unsafe {
ptr::copy_nonoverlapping(buf.as_ptr(), self.0, copy_size);
ptr::copy_nonoverlapping(buf.as_ptr() as _, self.0, copy_size);
self.1 -= copy_size;
self.0 = self.0.add(copy_size);