Feedback for first Rust Program

https://sh.itjust.works/post/57050433

@Yeahboy92 - sh.itjust.works

Lemmy

Only skimmed quickly.

  • Four different hex representations for the same 3 bytes is extremely wasteful. You don’t need to store more than a [u8; 3]. You can create a “mapped” struct with those representations if caching them is somehow useful for the use-case. And since we’re micro-optimizing memory usage, Box<str> instead of String would be more efficient since those values are not meant to be mutable. You can then serialize to one of the many efficient binary formats around (e.g. borsh). This is not JavaScript, so you can oftentimes not be bound to JSON.
  • Your parsing code looks both unrobust (potentially fragile hard-coded assumptions) and unnecessarily complex. Something much simpler can probably be done with some trivial regex usage.

Box<str> instead of String

I need to explore more about this. I really have no idea about this

Your parsing code looks both unrobust (potentially fragile hard-coded assumptions) and unnecessarily complex. Something much simpler can probably be done with some trivial regex usage.

My first approach is using regex, but it seems like overkill? because the data from standards-oui.ieee.org/oui/oui.txt is somehow already structured.

But i’ll try the regex approach later.

Thank you :D