From 6988bcd74c6ab85d0a5f85c8b96c61f7fb75ad1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Ochagav=C3=ADa?= Date: Mon, 21 Jul 2014 18:06:24 +0200 Subject: [PATCH] Implement Show for CString We use use `from_utf8_lossy` to convert it to a MaybeOwned string, to avoid failing in case the CString contains invalid UTF-8 --- src/librustrt/c_str.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/librustrt/c_str.rs b/src/librustrt/c_str.rs index 0f2fcaff310..c30b267219b 100644 --- a/src/librustrt/c_str.rs +++ b/src/librustrt/c_str.rs @@ -73,6 +73,7 @@ use collections::hash; use core::kinds::marker; use core::mem; use core::ptr; +use core::fmt; use core::raw::Slice; use core::slice; use core::str; @@ -344,6 +345,12 @@ impl Collection for CString { } } +impl fmt::Show for CString { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + String::from_utf8_lossy(self.as_bytes_no_nul()).fmt(f) + } +} + /// A generic trait for converting a value to a CString. pub trait ToCStr { /// Copy the receiver into a CString.