I love this pattern: excellent advice. I asked ChatGPT how to do this in Rust, and it suggested a template using a phantom type was idiomatic Rust:
pub struct ReadOnly;
pub struct Writable;
pub struct Store<Mode> {
file: File,
_mode: PhantomData<Mode>,
}
Then implement write() only in the writable specialization.
I've deferred this change for now, but congratulations: you are responsible for my first refactoring (once the implementation is complete!) 🧡
pub struct ReadOnly;
pub struct Writable;
pub struct Store<Mode> {
file: File,
_mode: PhantomData<Mode>,
}
Then implement write() only in the writable specialization.
I've deferred this change for now, but congratulations: you are responsible for my first refactoring (once the implementation is complete!) 🧡