Wow, I realize this post is 2 years old but hope Michael occasionally checks it. (He better I also bought the ebook to show my appreciation for this blog style tutorial). Since I am learning I came up with this way to solve building the frame:
let mut top_bottom = |dir: &str| {
if dir == "horiz" {
write!(fmt, "+");
for _ in 0..self.frame.width {
write!(fmt, "_");
}
write!(fmt, "+\n");
} else {
for row in 0..self.frame.height {
write!(fmt, "|");
for _ in 0..self.frame.width {
write!(fmt, " ");
}
write!(fmt, "|\n");
}
}
};
top_bottom("horiz");
top_bottom("vert");
Ok(top_bottom("horiz"))
}
My question? Is this a Rust acceptable way to do so. I ask because I am want to understand Rust and not just copy. I also ask because while this may work, Rust programmers may find this NOT idiomatic to Rust. I have found most languages have multiple way to solve things but one is frowned upon. For example, working with ReactJS, I found that React actually makes is fairly easy to manipulate the DOM directly, but the React creators and maintainers frown up on it because React should manipulate the DOM through its virtual DOM.
Let me know your thoughts.
Thanks!
--
You received this message because you are subscribed to the Google Groups "Begin Rust" group.
To unsubscribe from this group and stop receiving emails from it, send an email to begin-rust+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/begin-rust/2b898221-9c30-4efd-8f5e-9d343f85b9b8n%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.