aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Rémi Bardon <remi@remibardon.name>2025-05-25 11:39:01 +0000
committerLibravatar cel 🌸 <cel@bunny.garden>2025-05-30 21:56:44 +0100
commite1f4fbb65724fdfbce2068d3ee334eb4f60af37a (patch)
tree7192cb4468f62be27c0e663aeddcadda29e5bd39
parentf8f98b120d5bc66ac3459c7b135a89920109c765 (diff)
downloadpeanuts-main.tar.gz
peanuts-main.tar.bz2
peanuts-main.zip
chore: Do not require nightly RustHEADmain
-rw-r--r--src/writer.rs40
-rw-r--r--src/writer/loggable.rs4
2 files changed, 27 insertions, 17 deletions
diff --git a/src/writer.rs b/src/writer.rs
index 205ee7f..1818fca 100644
--- a/src/writer.rs
+++ b/src/writer.rs
@@ -534,9 +534,11 @@ impl<W: AsyncWrite + Unpin + Send> Writer<Loggable<W>> {
pub async fn write_full(&mut self, into_element: &impl IntoElement) -> Result<()> {
let element = into_element.into_element();
self.write_element(&element).await?;
- let bytes = &self.inner.ignore_end().take_log();
- let log = str::from_utf8(bytes).unwrap_or("failed to convert bytes written to str");
- info!("wrote element: {}", log);
+
+ let bytes = self.inner.ignore_end().take_log();
+ let log = String::from_utf8(bytes)
+ .map_err(|err| format!("failed to convert bytes written to str: {err}"));
+ info!("wrote element: {log:?}");
Ok(())
}
@@ -544,9 +546,11 @@ impl<W: AsyncWrite + Unpin + Send> Writer<Loggable<W>> {
pub async fn write_start(&mut self, into_element: &impl IntoElement) -> Result<()> {
let element = into_element.into_element();
self.write_element_start(&element).await?;
- let bytes = &self.inner.ignore_end().take_log();
- let log = str::from_utf8(bytes).unwrap_or("failed to convert bytes written to str");
- info!("wrote element start: {}", log);
+
+ let bytes = self.inner.ignore_end().take_log();
+ let log = String::from_utf8(bytes)
+ .map_err(|err| format!("failed to convert bytes written to str: {err}"));
+ info!("wrote element start: {log:?}");
Ok(())
}
@@ -555,9 +559,11 @@ impl<W: AsyncWrite + Unpin + Send> Writer<Loggable<W>> {
for content in &into_element.get_content() {
self.write_content(content).await?;
}
- let bytes = &self.inner.ignore_end().take_log();
- let log = str::from_utf8(bytes).unwrap_or("failed to convert bytes written to str");
- info!("wrote element content: {}", log);
+
+ let bytes = self.inner.ignore_end().take_log();
+ let log = String::from_utf8(bytes)
+ .map_err(|err| format!("failed to convert bytes written to str: {err}"));
+ info!("wrote element content: {log:?}");
Ok(())
}
@@ -565,18 +571,22 @@ impl<W: AsyncWrite + Unpin + Send> Writer<Loggable<W>> {
pub async fn write(&mut self, into_content: &impl IntoContent) -> Result<()> {
let content = into_content.into_content();
self.write_content(&content).await?;
- let bytes = &self.inner.ignore_end().take_log();
- let log = str::from_utf8(bytes).unwrap_or("failed to convert bytes written to str");
- info!("wrote element: {}", log);
+
+ let bytes = self.inner.ignore_end().take_log();
+ let log = String::from_utf8(bytes)
+ .map_err(|err| format!("failed to convert bytes written to str: {err}"));
+ info!("wrote element: {log:?}");
Ok(())
}
/// Navigate down the document structure and write the end tag for the current element opened in the document context.
pub async fn write_end(&mut self) -> Result<()> {
self.write_end_tag().await?;
- let bytes = &self.inner.ignore_end().take_log();
- let log = str::from_utf8(bytes).unwrap_or("failed to convert bytes written to str");
- info!("wrote element end: {}", log);
+
+ let bytes = self.inner.ignore_end().take_log();
+ let log = String::from_utf8(bytes)
+ .map_err(|err| format!("failed to convert bytes written to str: {err}"));
+ info!("wrote element end: {log:?}");
Ok(())
}
diff --git a/src/writer/loggable.rs b/src/writer/loggable.rs
index 82f14a3..1b9f64a 100644
--- a/src/writer/loggable.rs
+++ b/src/writer/loggable.rs
@@ -33,8 +33,8 @@ impl<W> Loggable<W> {
impl<W: AsyncWrite + Unpin + Send> Display for Loggable<W> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- let str = str::from_utf8(&self.log_buffer).unwrap_or("buffer to string conversion failed");
- f.write_str(str)
+ let str = String::from_utf8_lossy(&self.log_buffer);
+ write!(f, "{str}")
}
}