I get it, don't run a project if you see some bad code and question the quality of the project. Quality that very well could, and likely will, impact you. From bugs to performance. Don't run it, of course. But to attack it, seemingly with such personal zeal.. can people not improve?
I dunno, i guess i just don't feel the software we write on average is actually good. We make compromises and mistakes constantly. Our house is the purist of glass and many of us are just chucking stones like there's no tomorrow.
Lets take a step back. Breathe. Point out flaws by all means, but maybe reduce the often apparent revelry in someone else's mistake.
... sorry for the high horse rant. I'm nursing coffee and i've just seen it a lot with Lemmy/Kbin recently. Also this isn't pointed at anyone here directly.. just a pattern i feel i frequently see.
As long as nothing is depending on 'static lifetime further down the line. (EDIT: ignore and see below)
> (or at least increase the upper limit to 16)
That should be doable for sure. Even something like (I'm not a rust developer, just have a passing familiarity, so my syntax may be off):
IndentStyle::Spaces(n) if 0 < n && n <= 16 => &" "[0..n as usize],
I think that would condense it all down into one line, rather than having special cases for all of 1 through 16.EDIT: after toying around in the rust playground, I think the following will support any indent level (within the bounds of the u8 type).
At the top level:
static INDENTS: [u8: 256] = [' '; 256];
And then in the as_str function: IndentStyle::Spaces(n) => std::str::from_utf8(&INDENTS[0..n as usize]).unwrap() const INDENTS: [u8; 256] = [b' '; 256];
// ...
IndentStyle::Spaces(n) => unsafe { std::str::from_utf8_unchecked(&INDENTS[0..n as usize]) },
But I would consider having INDENTS be a &str to get the cheap slicing without needing unsafe. Since putting in a string literal of 256 spaces is nasty I would use the const_format crate to generate the constant: const INDENTS: &str = str_repeat!(" ", 256);If this was a carefully observed decision, one that is prone to looking odd, it deserves an explanation for future selves to not chase the rabbit of understanding.