From e420a0a5ac929df9e6e009f68d59af6899ca5209 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Arnaud Date: Mon, 5 Nov 2018 16:53:00 +0100 Subject: [PATCH] return error instead of panic --- yaserde/src/ser/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yaserde/src/ser/mod.rs b/yaserde/src/ser/mod.rs index d152b5a..4af91f0 100644 --- a/yaserde/src/ser/mod.rs +++ b/yaserde/src/ser/mod.rs @@ -7,7 +7,7 @@ use YaSerialize; pub fn to_string(model: &T) -> Result { let buf = Cursor::new(Vec::new()); - let cursor = serialize_with_writer(model, buf).unwrap(); + let cursor = serialize_with_writer(model, buf)?; let data = str::from_utf8(cursor.get_ref()).expect("Found invalid UTF-8"); Ok(String::from(data)) } @@ -22,7 +22,7 @@ pub fn serialize_with_writer(model: &T, writer: W) -> pub fn to_string_content(model: &T) -> Result { let buf = Cursor::new(Vec::new()); - let cursor = serialize_with_writer_content(model, buf).unwrap(); + let cursor = serialize_with_writer_content(model, buf)?; let data = str::from_utf8(cursor.get_ref()).expect("Found invalid UTF-8"); Ok(String::from(data)) }