diff --git a/src/lib.rs b/src/lib.rs index 8df2041..d9d7199 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,4 +40,7 @@ mod time; pub use time::dur; mod hash; -pub use hash::*; \ No newline at end of file +pub use hash::*; + +mod strings; +pub use strings::*; \ No newline at end of file diff --git a/src/strings.rs b/src/strings.rs new file mode 100644 index 0000000..0b45225 --- /dev/null +++ b/src/strings.rs @@ -0,0 +1,26 @@ +use core::fmt::{Debug, Display, Error, Formatter, Write}; +use core::ops::{ControlFlow, Deref}; + +#[repr(transparent)] +pub struct Wide<'a>(pub &'a [u16]); + +impl<'a> Display for Wide<'a> { + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { + let result = char::decode_utf16(self.0.iter().cloned()) + .map(|a| a.unwrap_or('?')) + .try_for_each(|c| match f.write_char(c) { + Ok(_) => ControlFlow::Continue(()), + Err(e) => ControlFlow::Break(e), + }); + match result { + ControlFlow::Continue(_) => Ok(()), + ControlFlow::Break(e) => Err(e) + } + } +} + + + + + +