You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Regarding the read-only storage trait split discussed in #9, I have two use cases:
Read-only memory: For chips that really cannot be reprogrammed after leaving the factory, it would be nicer if any attempt to do a write() would simply not compile, rather than adding some kind of UnsupportedOperation error variant (which now you need to handle) or panicking at runtime.
Lockable memory: For chips that provide lockable memory, initially the driver could provide an struct implementing only ReadOnlyStorage.
2a. Then on an unlock() driver method, it can transform that into one implementing the full ReadWriteStorage.
2b. When done, another lock() method can transform that into a ReadOnlyStorage.
In several drivers I have written a somewhat similar implementation of (2), offering only some of the operations depending on the mode. See for example this driver.
Advantadges
Support ROM natively.
Impossible to run the wrong operation for the mode the device is in as the code will not compile.
Skip that OopsWrongMode error variant or panics and any runtime handling thereof.
Disadvantadges
Locking/unlocking dance is more complicated than when just returning an error, especially around error recovery.
Devices/setups where the memory does a reset independently of the software need to be modeled correctly by the driver/app or cannot use the ReadOnly version, depending on how the system works.
PS: Please feel free to choose different names.
The text was updated successfully, but these errors were encountered:
Regarding the read-only storage trait split discussed in #9, I have two use cases:
write()
would simply not compile, rather than adding some kind ofUnsupportedOperation
error variant (which now you need to handle) or panicking at runtime.ReadOnlyStorage
.2a. Then on an
unlock()
driver method, it can transform that into one implementing the fullReadWriteStorage
.2b. When done, another
lock()
method can transform that into aReadOnlyStorage
.In several drivers I have written a somewhat similar implementation of (2), offering only some of the operations depending on the mode. See for example this driver.
Advantadges
OopsWrongMode
error variant or panics and any runtime handling thereof.Disadvantadges
ReadOnly
version, depending on how the system works.PS: Please feel free to choose different names.
The text was updated successfully, but these errors were encountered: