How to use fmt::Display with an iterator?

Hello everyone,

This is rather simple but I can’t wrap my head around it. I’m implementing the Rubik’s Cube like this:

// Each Cubie has a set of xyz coordinates
struct Cubie {
    xyz: [i8; 3],
    xyz_color: [Color; 3], // Color is an enum, it implements #[derive(Debug)]
struct Cube {
    cubies: Vec<Cubie>,

And I want to display it like this:

impl fmt::Display for Cube {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        for cubie in self.cubies.iter() {

But rustc tells me:

| |______^ expected enum `std::result::Result`, found ()

Is this because I’m iterating over a vector? What can I do?

you need ?; after the write! call

EDIT and an Ok(()) at the end

1 Like

Thank you very much, I’m still having trouble with this Result<(), E> syntax.
Have a nice day!

1 Like

It’s awesome once you get used to it :slight_smile: