|
|
@ -1,8 +1,10 @@ |
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only
|
|
|
|
// SPDX-FileCopyrightText: 2023 Denis Drakhnia <numas13@gmail.com>
|
|
|
|
// SPDX-FileCopyrightText: 2023 Denis Drakhnia <numas13@gmail.com>
|
|
|
|
|
|
|
|
|
|
|
|
use std::io::{self, Write as _}; |
|
|
|
use std::{ |
|
|
|
use std::{fmt, mem, str}; |
|
|
|
fmt::{self, Write}, |
|
|
|
|
|
|
|
mem, str, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
use thiserror::Error; |
|
|
|
use thiserror::Error; |
|
|
|
|
|
|
|
|
|
|
@ -482,9 +484,7 @@ impl<'a> CursorMut<'a> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn put_as_str<T: fmt::Display>(&mut self, value: T) -> Result<&mut Self, Error> { |
|
|
|
pub fn put_as_str<T: fmt::Display>(&mut self, value: T) -> Result<&mut Self, Error> { |
|
|
|
let mut cur = io::Cursor::new(&mut self.buffer[self.pos..]); |
|
|
|
write!(self, "{}", value).map_err(|_| Error::UnexpectedEnd)?; |
|
|
|
write!(&mut cur, "{}", value).map_err(|_| Error::UnexpectedEnd)?; |
|
|
|
|
|
|
|
self.pos += cur.position() as usize; |
|
|
|
|
|
|
|
Ok(self) |
|
|
|
Ok(self) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -507,6 +507,14 @@ impl<'a> CursorMut<'a> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl fmt::Write for CursorMut<'_> { |
|
|
|
|
|
|
|
fn write_str(&mut self, s: &str) -> fmt::Result { |
|
|
|
|
|
|
|
self.put_bytes(s.as_bytes()) |
|
|
|
|
|
|
|
.map(|_| ()) |
|
|
|
|
|
|
|
.map_err(|_| fmt::Error) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)] |
|
|
|
#[cfg(test)] |
|
|
|
mod tests { |
|
|
|
mod tests { |
|
|
|
use super::*; |
|
|
|
use super::*; |
|
|
|