adamfortune.bsky.social
@adamfortune.bsky.social
Unless you really need random access of lots of characters, probably .chars().nth(). It’ll be O(n), but won’t panic. Anything more sophisticated and you’re probably going to have to devise a more complex solution. UTF8 isn’t really built for random access.
December 24, 2025 at 10:21 PM
I think slicing is fine, just make sure the indexes you’re using come directly from the .len() or .char_indices() functions. The problems happen when you start adding values to the byte indexes.
December 24, 2025 at 6:58 PM
I think you could replace starting at .collect() with

.map(|result| result .map(/* your Ok value logic */))
.take_until(|result| result .is_err()
.fold(|result| { let aggregate = result?/* rest of the fold logic here */ })

I use [take_until](docs.rs/take-until/l...), but take_while could work too
TakeUntilExt in take_until - Rust
TakeUntilExt is an extension trait for iterators. It adds the `Self::take_until` method.
docs.rs
December 4, 2025 at 1:27 PM
If I remember correctly, Result is an IntoIterator type, so you could flat_map instead of map if you’re just trying to ignore the Err’s.
December 4, 2025 at 3:58 AM
This is a solved problem. Check out serde.rs/attr-flatten...
Struct flattening · Serde
serde.rs
October 31, 2025 at 2:37 AM
I always struggle to stay motivated beyond ~day 12. Maybe I’ll actually finish AOC this year!
October 26, 2025 at 12:43 PM