diff --git a/examples/doc_macro_show.rs b/examples/doc_macro_show.rs index 36635f1..a12244c 100644 --- a/examples/doc_macro_show.rs +++ b/examples/doc_macro_show.rs @@ -10,7 +10,7 @@ fn main() { // This will write "1 2\n3 4\n" to the standard output. show!([[1, 2], [3, 4]]); // This will write "1, 2\n3, 4\n" to the standard output. - show!([[1, 2], [3, 4]], sep=["\n", ", "]); + show!([[1, 2], [3, 4]], sep = ["\n", ", "]); // This will write "1, 2\n3, 4!" to the standard output. - show!([[1, 2], [3, 4]], sep=["\n", ", "], end="!"); + show!([[1, 2], [3, 4]], sep = ["\n", ", "], end = "!"); } diff --git a/src/write/mod.rs b/src/write/mod.rs index f39fd17..df1af2e 100644 --- a/src/write/mod.rs +++ b/src/write/mod.rs @@ -67,18 +67,6 @@ pub trait WriteInto: Rank { } } -// impl WriteInto for T { -// #[inline] -// fn try_write_into_with_sep( -// &self, -// s: &mut S, -// sep: &[impl Separator], -// ) -> Result<()> { -// debug_assert!(sep.is_empty()); -// self.try_write_one_into(s) -// } -// } - impl WriteInto for &T { #[inline] fn try_write_into_with_sep( diff --git a/src/write/sep_by.rs b/src/write/sep_by.rs index 474c3c9..8e2d954 100644 --- a/src/write/sep_by.rs +++ b/src/write/sep_by.rs @@ -70,7 +70,6 @@ impl + Clone, T: WriteInto, S: Separator + ?Sized> WriteIn residual: &[impl Separator], ) -> super::Result { let mut iter = self.iter.clone(); - // eprintln!("sep: {:?}; residual: {:?}", self.sep, residual); if let Some(first) = iter.next() { first.try_write_into_with_sep(s, residual)?; } diff --git a/src/write/separator.rs b/src/write/separator.rs index fc3d09e..5e8bc08 100644 --- a/src/write/separator.rs +++ b/src/write/separator.rs @@ -37,45 +37,6 @@ pub trait GetDefaultSeparator { const DEFAULT_SEPARATOR: &'static [Self::Separator]; } -// impl GetDefaultSeparator for T0 { -// type Separator = &'static str; -// const DEFAULT_SEPARATOR: &'static [&'static str] = &[]; -// } - -// macro_rules! impl_rank1 { -// ($ty:ty, $($tt:tt)*) => { -// impl GetDefaultSeparator for $ty { -// type Separator = &'static str; -// const DEFAULT_SEPARATOR: &'static [&'static str] = &[" "]; -// } -// }; -// } - -// impl_rank1!(Vec,); -// impl_rank1!([T0; N], const N: usize); -// impl_rank1!([T0],); - -// macro_rules! impl_rank2 { -// ($ty:ty, $($tt:tt)*) => { -// impl GetDefaultSeparator for $ty { -// type Separator = &'static str; -// const DEFAULT_SEPARATOR: &'static [&'static str] = &[" ", "\n"]; -// } -// }; -// } - -// impl_rank2!(Vec>, ); -// impl_rank2!([Vec], ); -// impl_rank2!([Vec; N], const N: usize); - -// impl_rank2!(Vec<[T0; M]>, const M: usize); -// impl_rank2!([[T0; M]], const M: usize); -// impl_rank2!([[T0; M]; N], const M: usize, const N: usize); - -// impl_rank2!(Vec<&[T0]>, ); -// impl_rank2!([&[T0]], ); -// impl_rank2!([&[T0]; N], const N: usize); - const fn get_rank(rank: usize, space: bool) -> &'static [&'static str] { match (rank, space) { (0, _) => &[], diff --git a/tests/array.rs b/tests/array.rs index 4ce4471..5673ce8 100644 --- a/tests/array.rs +++ b/tests/array.rs @@ -121,13 +121,22 @@ fn display() { assert_eq!(s.try_write_into_string_with_sep(&[" "]).unwrap(), "1 2 3"); let s = [[1, 2, 3], [4, 5, 6]]; - assert_eq!(s.try_write_into_string_with_sep(&["\n", " "]).unwrap(), "1 2 3\n4 5 6"); + assert_eq!( + s.try_write_into_string_with_sep(&["\n", " "]).unwrap(), + "1 2 3\n4 5 6", + ); let s = [[1, 2], [3, 4]]; - assert_eq!(s.try_write_into_string_with_sep(&["\n", " "]).unwrap(), "1 2\n3 4"); + assert_eq!( + s.try_write_into_string_with_sep(&["\n", " "]).unwrap(), + "1 2\n3 4", + ); let s = [[1, 2]]; - assert_eq!(s.try_write_into_string_with_sep(&["\n", " "]).unwrap(), "1 2"); + assert_eq!( + s.try_write_into_string_with_sep(&["\n", " "]).unwrap(), + "1 2", + ); let s: [[usize; 0]; 0] = []; assert_eq!(s.try_write_into_string_with_sep(&[" "]).unwrap(), ""); diff --git a/tests/slice.rs b/tests/slice.rs index e69de29..bfb1053 100644 --- a/tests/slice.rs +++ b/tests/slice.rs @@ -0,0 +1,27 @@ +use iof::{show, unwrap, WriteInto}; + +#[test] +fn write_into() { + let buf = unwrap!([1, 2, 3, 4].as_slice().try_write_into_string()); + assert_eq!(buf, "1 2 3 4"); + let buf = unwrap!([1, 2].as_slice().try_write_into_string()); + assert_eq!(buf, "1 2"); + let buf = unwrap!([1].as_slice().try_write_into_string()); + assert_eq!(buf, "1"); + let buf = unwrap!([0i32; 0].as_slice().try_write_into_string()); + assert_eq!(buf, ""); + + let buf = unwrap!(['1', '2', '3', '4'].as_slice().try_write_into_string()); + assert_eq!(buf, "1234"); + let buf = unwrap!(['1', '2'].as_slice().try_write_into_string()); + assert_eq!(buf, "12"); + let buf = unwrap!(['1'].as_slice().try_write_into_string()); + assert_eq!(buf, "1"); + let buf = unwrap!(['1'; 0].as_slice().try_write_into_string()); + assert_eq!(buf, ""); +} + +#[test] +fn show() { + show!([1, 2, 3, 4].as_slice()); +} diff --git a/tests/string.rs b/tests/string.rs index cdcbdae..b2b457e 100644 --- a/tests/string.rs +++ b/tests/string.rs @@ -159,5 +159,8 @@ fn string() { let mut buf = Cursor::new(Vec::new()); show!("Hello, World!", end = "" => &mut buf); show!("🦀🦀🦀", => &mut buf); - assert_eq!(unwrap!(String::from_utf8(buf.into_inner())), "Hello, World!🦀🦀🦀\n"); + assert_eq!( + unwrap!(String::from_utf8(buf.into_inner())), + "Hello, World!🦀🦀🦀\n", + ); }