Everything got better when I became a green-haired 2D girl. I do fun and unusual things with video games and pinball.

cohost inspired me to do more. Thank you



I forgot to mention the greatest thing that happened in Advent of Code day 7, when the "filesystem" my code produced didn't have quite enough stuff in it (because I was not handling the first thing I saw in each directory correctly).

I was getting despondent that I'd have to write some output code to show a nicely indented directory tree. But, as a first step, I added dbg!(filesystem); to my code.

The dbg! macro is a really ergonomic form of print debugging: it prints out the line number you're on, the expression inside, and the expression's value, using a formatter that can be "derived" (automatically implemented) for most types. I figured it would be a mess that maybe I could squint at and understand the structure, like a Python repr(). What I got was


[src/main.rs:215] filesystem = Dir {
    contents: {
        "b.txt": File {
            size: 14848514,
        },
        "d": Dir {
            contents: {
                "d.log": File {
                    size: 8033020,
                },
                "k": File {
                    size: 7214296,
                },
                "d.ext": File {
                    size: 5626152,
                },
            },
        },
        "c.dat": File {
            size: 8504156,
        },
        "a": Dir {
            contents: {
                "h.lst": File {
                    size: 62596,
                },
                "g": File {
                    size: 2557,
                },
            },
        },
    },
}

It's the filesystem! It's indented in a way that's really readable! The automatic implementation of Debug I got for a type I had just defined is that good.

I quickly found the missing file entries and fixed the problem. Thanks, Rust.


You must log in to comment.

in reply to @arborelia's post: