I keep getting surprised by .lines() semantics in Rust.
"" -> empty
"foo" -> one line
"foo\n" -> one line
"foo\nbar" -> two lines
I end up using .split('\n') everywhere instead, but .lines() is so convenient it feels like a footgun.
miniblog.
Related Posts
When talking about a match or a switch statement, I've typically seen people talk about individual 'cases' or 'arms'.
TIL Zig uses 'prongs' instead!
Today I learnt about clippy::clone_on_ref_ptr, which complains about t.clone() on a Rc<Thing>. You write Rc::clone(t) instead, so it's obvious it's a cheap clone.
It's a nice approach, because it makes the expensive clones more obvious.
I'm writing a Path type in my programming language but not sure what methods belong on a Path.
Should I have some_path.read_string() or fs::read_string(some_path) instead?
I love .method() for IDE completion, but I don't want Path to be cluttered. I'm also trying to avoid UFCS.