Record Simplification

  • For the Default implementation for RecordData, changed RecordData to Self to improve code interpretability and to make the code more idiomatic.
  • Refactored the checksum into a struct. This provides better type-safety (this prevents us from accidentally passing in a u32 for something else when what we really want is a Checksum). This also makes the code more readable, as if we see a Checksum being passed around it is much clearer than an unnamed u32, additionally this will catch errors in future version, improving how maintenanceable the code is.
    • Updated the corresponding types and update the parsing.
  • Removed the database field from the RecordData struct as it is never actually used for anything and is always a blank string. This simplifies the code base as there are less ambigious things.
  • Removed the location field as it was either zero but was never read or written.
  • Removed the location_type field as it was always zero and never written or read.
  • Added a constructor for creating RecordCharacteristics where everything is zeroed except for the counter number which seems to be a common pattern.
  • Changed methods in RecordData that are intended to take Path-like objects to accept these objects instead of just strings. This makes the code more flexible and it is clearer that paths are intended, while not breaking existing code.
  • Moved the save_hash_database method inside of the same module as RecordData and made it private as the intention of the save method on the RecordData class is for the function to be called on the struct directly, improving code readability.
  • This was also done for load_hash_database and load_hash_database_readonly, although the latter was removed as it is the first but just reaonly, it is quicker to just call RecordData::load(x).read_only() to get the readonly version. This removes code duplication and removes the surface for bugs.
    • These were converted into the struct methods RecordData::load and RecordData::load_read_only respectively. This is much more readable and when modifying there are not many disjoint methods that do the same thing. (load_hash_database and load_hash_database_readonly did the same thing, just made a slight change to the result as at the end.)
    • When loading databases, they now take the generic P where P is something that can be referenced to get a Path. This has the same advantages as when it was done for the save methods.

Merge request reports

Loading