mirror of
https://github.com/rust-embedded/heapless.git
synced 2025-09-29 05:20:32 +00:00
implement Display for String
This commit is contained in:
parent
f2cad2fc55
commit
ce6a4a2a2b
@ -407,7 +407,17 @@ where
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let slice: &str = &**self;
|
||||
slice.fmt(f)
|
||||
fmt::Debug::fmt(slice, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> fmt::Display for String<N>
|
||||
where
|
||||
N: ArrayLength<u8>,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let slice: &str = &**self;
|
||||
fmt::Display::fmt(slice, f)
|
||||
}
|
||||
}
|
||||
|
||||
@ -538,6 +548,18 @@ mod tests {
|
||||
assert_eq!("\"abcd\"", std_s);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn display() {
|
||||
extern crate std;
|
||||
|
||||
use core::fmt::Write;
|
||||
|
||||
let s: String<U8> = String::from("abcd");
|
||||
let mut std_s = std::string::String::new();
|
||||
write!(std_s, "{}", s).unwrap();
|
||||
assert_eq!("abcd", std_s);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty() {
|
||||
let s: String<U4> = String::new();
|
||||
|
Loading…
x
Reference in New Issue
Block a user