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
As the comment notes, we intended to replace this Box<dyn ...> with a generic associated type (GAT), so implementations of IonReader could supply a concrete Iterator implementation. However, we cannot do that for this particular method because we need the IonReader trait to be object safe. For the moment, traits that use GATs are not object safe. See also: rust-lang/rust#81823.
Iterating over a value's annotations shouldn't require the expense of Box<dyn>, so we need to replace this with a concrete implementation that would work for all reader implementations.
@almann had a good suggestion for this--add a method like this to IonReader:
This method would require reader implementations to maintain a small amount of state to track which annotations have been read. When reading the value foo::bar::5, calling read_annotation() once would return Ok(Some(foo)), calling it a second time would return Ok(Some(bar)), and calling it a third time would return Ok(None).
Having this method available in all IonReader implementations would allow us to provide a concrete, stack-allocated, statically-dispatched AnnotationsIterator type that worked for all readers.
The text was updated successfully, but these errors were encountered:
Currently the
IonReader
trait includes anannotations()
method that returns aBox<dyn Iterator<_>>
over the current value's annotations:ion-rust/src/stream_reader.rs
Lines 42 to 46 in 4f2eae6
As the comment notes, we intended to replace this
Box<dyn ...>
with a generic associated type (GAT), so implementations ofIonReader
could supply a concreteIterator
implementation. However, we cannot do that for this particular method because we need theIonReader
trait to be object safe. For the moment, traits that use GATs are not object safe. See also: rust-lang/rust#81823.Iterating over a value's annotations shouldn't require the expense of
Box<dyn>
, so we need to replace this with a concrete implementation that would work for all reader implementations.@almann had a good suggestion for this--add a method like this to
IonReader
:This method would require reader implementations to maintain a small amount of state to track which annotations have been read. When reading the value
foo::bar::5
, callingread_annotation()
once would returnOk(Some(foo))
, calling it a second time would returnOk(Some(bar))
, and calling it a third time would returnOk(None)
.Having this method available in all
IonReader
implementations would allow us to provide a concrete, stack-allocated, statically-dispatchedAnnotationsIterator
type that worked for all readers.The text was updated successfully, but these errors were encountered: