use iof::{dimension::Dimension, show, unwrap, Separators, WriteInto}; use std::{io, str::from_utf8}; /// A compact and sorted container. struct CustomContainer { data: Vec, } impl FromIterator for CustomContainer { fn from_iter>(iter: T) -> Self { let mut data: Vec = iter.into_iter().collect(); data.sort(); Self { data } } } impl Dimension for CustomContainer { const DIMENSION: usize = 1; const SPACE: bool = false; } impl WriteInto for CustomContainer { fn try_write_into_with_sep( &self, s: &mut S, _sep: impl Separators, ) -> io::Result<()> { self.data .try_write_into_with_sep(s, &[Self::get_default_separator()]) } } #[test] fn show() { let data = CustomContainer::from_iter([9, 8, 7, 6, 5, 4, 3, 2, 1, 0]); let mut buf = Vec::new(); show!(data => buf); assert_eq!(unwrap!(from_utf8(&buf)), "0123456789\n"); }