1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
use { ListSeparator, Points, WriteBuffer, WriteOptions, }; impl WriteBuffer for (f64, f64) { fn write_buf_opt(&self, opt: &WriteOptions, buf: &mut Vec<u8>) { self.0.write_buf_opt(opt, buf); match opt.list_separator { ListSeparator::Space => buf.push(b' '), ListSeparator::Comma => buf.push(b','), ListSeparator::CommaSpace => buf.extend_from_slice(b", "), } self.1.write_buf_opt(opt, buf); } } impl_display!(Points); impl_debug_from_display!(Points); #[cfg(test)] mod tests { use super::*; #[test] fn write_1() { let list = Points(vec![(1.0, 2.0), (3.0, 4.0)]); let mut opt = WriteOptions::default(); opt.list_separator = ListSeparator::Space; assert_eq!(list.with_write_opt(&opt).to_string(), "1 2 3 4"); } #[test] fn write_2() { let list = Points(vec![(1.0, 2.0), (3.0, 4.0)]); let mut opt = WriteOptions::default(); opt.list_separator = ListSeparator::Comma; assert_eq!(list.with_write_opt(&opt).to_string(), "1,2,3,4"); } #[test] fn write_3() { let list = Points(vec![(1.0, 2.0), (3.0, 4.0)]); let mut opt = WriteOptions::default(); opt.list_separator = ListSeparator::CommaSpace; assert_eq!(list.with_write_opt(&opt).to_string(), "1, 2, 3, 4"); } }