Add fallback for as_trusted_for calls#185
Conversation
c46c523 to
bd862fe
Compare
bd862fe to
98ca9e4
Compare
|
This is an interesting idea. My concern with this particular implementation / API is that it will make trusted usage more cumbersome to deal with. In particular, In this spirit of this direction, we could add an additional method on |
Right, I suppose this is equivalent to calling That value won't be a constant though, since size of available "readily-available" data is runtime dependent.
Aha, so this means:
|
|
I was wondering if we really need the "Trusted" machinery at the level of From what I understand the difficulty lies in deciding whether the obtained slice should be temporarily ( An idea - what if we:
|
|
We discussed with Zach the alternative API to
I guess we will still benefit from having trusted reader over such known-size slices. For example struct Element {
a: [u8; 12],
b: u64,
c: [u32; 3]
}
struct Elements(Vec<Element>);will obtain chunks of 32 bytes, but when populating each In short - we could just return equivalent of In the meantime I will close this PR, since we have better solution on the horizon. |
Callers of
as_trusted_forshould handle cases whereReaderimplementation isn't able to provide full buffer of desired size immediately. They should fallback to not using trusted reader in that case (slower, but still functional path).Current API is almost ready for this pattern, since
as_trusted_forreturns aResultand its documentation kind of imply that if reader cannot satisfy the request, it should return error. However falling back to different way of reading for all errors could be wrond, since some errors are logic errors or underlying IO errors, which should cause immediate break and propagating errors up.For this purpose special
ReadErrorvariant is introduced to mark recoverable error for too largeas_trusted_forrequest.Additionally it's imaginable that readers would be able to fulfill a smaller request for trusted reader and caller could adjust the request to still avoid bounds for whatever buffer space is available in the reader. Thus the recoverable error contains
usizewith the limit of currently available "trusted bytes" in case caller wants to loop and pick fast / slow path depending on such size.