Idiomatic way to avoid match

Also code reuse(in case later on you need the same functionality) is suffering etc.

I totally agree about readability, but this part feels like a solid YAGNI case. It's usually it's unwise to extract functions based on speculations of what might be needed later on. Instead, make the code flexible enough that you can extract that function at the moment you actually need to use it elsewhere.

Typically when I pull code out into its own function it's not because I'm thinking I might need it again later. Mostly it's because it does something that I can give a sensible name to, by making a function/method it gets a meaningful name and so removes the need for so much commenting to explain what is going on. On the road to self documenting code.

The second motivation is just moving some messy detail out of the the main flow of the calling function to aid clarification.

I think arnie's example demonstrates both these motivations.

I would have thought that if I was thinking I would need it again it would have to get pulled all the way out into it's own crate so as to make it reusable.

2 Likes

He already is duplicating code, in the same function...

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.