HdrHistogram_rust icon indicating copy to clipboard operation
HdrHistogram_rust copied to clipboard

Express auto resize functionality as a type?

Open marshallpierce opened this issue 7 years ago • 2 comments

While working on #10 I'm ending up with error options that can only occur if resize is disabled. This is unfortunate as it means that someone using resize will now have to handle error variants that won't ever occur at runtime.

The way that auto resize interacts with the contracts of the methods is a little regrettable to begin with. I wonder if there's a way we could reflect this difference in the type system rather than with comments here and there describing what will or won't happen when auto resize is enabled. Maybe a trait with associated types for errors and implementations for both auto resize and plain histograms? Almost all the code could be re-used between the two, I think, with just some different error enums to give each style a very precise error mapping.

marshallpierce avatar Feb 19 '17 02:02 marshallpierce

Mmm, I like that idea. I'm not sure we could actually use an enum for this, since Rust doesn't currently consider enum variants separate types (https://github.com/rust-lang/rfcs/pull/1450), but we could probably get away with using two unit structs, and impl the relevant methods only for one or the other.

My biggest concern would be that the place where we need separate impls would be for, say, the record, methods. However, there are also a bunch of other methods that also use the record methods, and they would need to have different impls too. You're probably right that we might be able to factor this out in a clever way though.

jonhoo avatar Feb 19 '17 06:02 jonhoo

Another wrinkle to think about: auto-resize is not serialized (and therefore not deserialized), which makes me lean a little more towards making auto resize a wrapper or something like that so that a deserialized histogram really could be 100% identical to its original version.

marshallpierce avatar Mar 10 '17 21:03 marshallpierce