-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mode types #13
base: master
Are you sure you want to change the base?
Mode types #13
Conversation
I'm ambivalent about this change. On one hand, having separate traits for Read/Write makes sense, but I think this implementation right now is a bit "over complex" for what it is trying to archive. This is mainly relating to the |
Yeah I was disappointed by how complex that got too. I'll have a think if there's anything I can do to simplify it. |
OK I've gotten rid of two traits, ReaderMode and WriterMode. I think that's as good as it gets. Clone and PartialEq are both object-unsafe, so we can't just store a
I think, of these, the enum (1) is the best option. The documentation is simple and clear, it's a tiny amount of code (25 lines of boilerplate and that's it) and everything happens in the type system so there's no need for any |
I refactored all the trajectory types to only implement the methods that were appropriate for the file mode it was opened in. This requires a lot of traits but means that mode checks happen at compile time rather than run time. Rust's type inference is really good, so all of the examples still work without modification :) Tests only needed changes to expected error types or construction of the private XdrFile struct, which doesn't have the open_read etc methods, which needed an explicit annotation. But neither of those things are things users would do, so this change should be a big plus for usability: No extra complications as long as you continue to use the open_read, open_append and open_write methods to construct trajectories, and statically checked file modes. Should even be faster and smaller in memory (by like a byte :P)
I also renamed XDRFile, XTCTrajectory and TRRTrajectory to XdrFile, XtcTrajectory and TrrTrajectory (which did require two changes to examples, just for clarity). This is in line with the Rust naming conventions:
This is an alternative to #11