From c1dbb2caa3606a874f2f70ff07d86614e9f4fff1 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 29 Oct 2022 20:01:36 +0100 Subject: [PATCH] wip --- src/bin/vertices.rs | 9 +-------- src/lib.rs | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/bin/vertices.rs b/src/bin/vertices.rs index a60c8e8..5492a1f 100644 --- a/src/bin/vertices.rs +++ b/src/bin/vertices.rs @@ -2,15 +2,8 @@ use z3_treefoil::*; fn main() -> io::Result<()> { - let mut o = io::stdout().lock(); for shape in read_vertices() { - for vx in shape { - for c in vx { - write!(o, "{}", c)?; - } - write!(o, ",")?; - } - write!(o, "\n")?; + print_shape(&shape)?; } Ok(()) diff --git a/src/lib.rs b/src/lib.rs index 07f20b1..87a9c47 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,8 +8,9 @@ pub fn default() -> T { Default::default() } pub const DIM: usize = 3; pub type Coord = i8; pub type Point = [Coord; DIM]; +pub type Shape = Vec; -pub fn read_vertices() -> impl Iterator> { +pub fn read_vertices() -> impl Iterator { io::stdin().lines().map(|l| { let l = l.unwrap(); let mut current: Point = default(); @@ -22,3 +23,15 @@ pub fn read_vertices() -> impl Iterator> { }).collect() }) } + +pub fn print_shape(shape: &Shape) -> io::Result<()> { + let mut o = io::stdout().lock(); + for vx in shape { + for c in vx { + write!(o, "{}", c)?; + } + write!(o, ",")?; + } + write!(o, "\n")?; + Ok(()) +} -- 2.30.2