Skip to content

Commit

Permalink
Remove unused codes and format codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheVeryDarkness committed Oct 6, 2024
1 parent 5023463 commit 45ef6ef
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 58 deletions.
4 changes: 2 additions & 2 deletions examples/doc_macro_show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "!");
}
12 changes: 0 additions & 12 deletions src/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,6 @@ pub trait WriteInto: Rank {
}
}

// impl<T: WriteOneInto> WriteInto for T {
// #[inline]
// fn try_write_into_with_sep<S: Write + ?Sized>(
// &self,
// s: &mut S,
// sep: &[impl Separator],
// ) -> Result<()> {
// debug_assert!(sep.is_empty());
// self.try_write_one_into(s)
// }
// }

impl<T: WriteInto + ?Sized> WriteInto for &T {
#[inline]
fn try_write_into_with_sep<S: Write + ?Sized>(
Expand Down
1 change: 0 additions & 1 deletion src/write/sep_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ impl<I: Iterator<Item = T> + 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)?;
}
Expand Down
39 changes: 0 additions & 39 deletions src/write/separator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,45 +37,6 @@ pub trait GetDefaultSeparator {
const DEFAULT_SEPARATOR: &'static [Self::Separator];
}

// impl<T0: Rank0 + ?Sized> GetDefaultSeparator for T0 {
// type Separator = &'static str;
// const DEFAULT_SEPARATOR: &'static [&'static str] = &[];
// }

// macro_rules! impl_rank1 {
// ($ty:ty, $($tt:tt)*) => {
// impl<T0: Rank0, $($tt)*> GetDefaultSeparator for $ty {
// type Separator = &'static str;
// const DEFAULT_SEPARATOR: &'static [&'static str] = &[" "];
// }
// };
// }

// impl_rank1!(Vec<T0>,);
// impl_rank1!([T0; N], const N: usize);
// impl_rank1!([T0],);

// macro_rules! impl_rank2 {
// ($ty:ty, $($tt:tt)*) => {
// impl<T0: Rank0, $($tt)*> GetDefaultSeparator for $ty {
// type Separator = &'static str;
// const DEFAULT_SEPARATOR: &'static [&'static str] = &[" ", "\n"];
// }
// };
// }

// impl_rank2!(Vec<Vec<T0>>, );
// impl_rank2!([Vec<T0>], );
// impl_rank2!([Vec<T0>; 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, _) => &[],
Expand Down
15 changes: 12 additions & 3 deletions tests/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(), "");
Expand Down
27 changes: 27 additions & 0 deletions tests/slice.rs
Original file line number Diff line number Diff line change
@@ -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());
}
5 changes: 4 additions & 1 deletion tests/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
}

0 comments on commit 45ef6ef

Please sign in to comment.