Hi folks,

I'm nearing the end of a major overhaul to what has become quite a large library (redbook for handling cd audio).

The crate covers 3 key domains:

  • hardware access
  • logical representation of a CD (named tracks etc. - all the stuff that would be printed on the disc / booklet / case)
  • technical information read from a CD (table-of-contents entries, time formats, etc.)

Plus a few key types which combine all of the above (e.g. an AudioCd which represents a disc in a drive)

The implementation is split nicely into logical modules (I'm happy with that).

I also have a detailed error tree.[1]

Where I'd like your opinions:

  1. There are about a dozen fundamental types which are defined in modules but to my mind deserve representation at the crate level. E.g. toc::TrackNo. If I re-export then they are effectively namable in two places (redbook::TrackNo & redbook::toc::TrackNo).[2] Do you prefer:
    • only one way to name every type (no re-exports)
    • only one way to name every type (re-export a pub(crate), leaving companion types with longer paths)
    • re-export - let the documentation list under "re-exports"
    • re-export & doc(inline)
  2. Right now I have the errors embedded in the main module hierarchy: redbook::error::EncodingError and redbook::toc::error::InvalidTrackNo. I'm wondering whether to move or duplicate the locations. So for the type stored in a redbook::Error::TocError(TocError::InvalidTrackNo(InvalidTrackNo(value: u8))):
    • keep in main hierarchy: redbook::toc::error::InvalidTrackNo
    • have a separate error hierarchy that matches the enum nesting: redbook::error::toc::InvalidTrackNo
    • duplicate hierarchies: define in one place, re-export in the other

  1. One thing I hate is being forced into lossy error handling when working with libraries which expose multi-level APIs but not multi-level errors. ↩︎

  2. I see this pattern a lot and sometimes it is confusing (very occasionally the types are identical so I end up double-checking all cases), at the same time it is common and helps with finding the key types in a crate. ↩︎

3 posts - 3 participants

Read full topic