This is an automated archive made by the Lemmit Bot.

The original was posted on /r/rust by /u/NotAXenophile on 2024-01-08 17:59:07.


Sorry if this is a dumb question but i’ve just started learning rust and today was the first time that I needed to use fmt::Display. The code compiles without any errors but it hits a stack overflow almost instantly on runtime. I’ve dug around a bit online but all of the resources I found for this kind of error all either flew over my head or were unrelated. As far as I can tell i’ve pretty much just implimented the Rust by Example implimentation so i’m a little unsure as to what could even be going wrong.

Apologies/thanks in advance.

use std::fmt;

fn main() {
    let c = Cave{map: [[[false; 512]; 512]; 512]};
    println!("{}", c);
}

#[derive(Debug)]
struct Cave{
    map: [[[bool; 512]; 512]; 512]
}

impl fmt::Display for Cave {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "({:?})", self)
    }
}