diff --git a/src/lazy/streaming_raw_reader.rs b/src/lazy/streaming_raw_reader.rs index ffc20c02..9233d8d7 100644 --- a/src/lazy/streaming_raw_reader.rs +++ b/src/lazy/streaming_raw_reader.rs @@ -120,10 +120,6 @@ impl StreamingRawReader { self.read_next(context, /*is_peek=*/ true) } - fn input_is_streaming(&mut self) -> bool { - self.input.get_mut().is_streaming() - } - fn read_next<'top>( &'top mut self, context: EncodingContextRef<'top>, @@ -131,7 +127,7 @@ impl StreamingRawReader { ) -> IonResult> { // If the input is a stream, we assume there may be more data available. // If it's a fixed slice, we know it's already complete. - let mut input_source_exhausted = !self.input_is_streaming(); + let mut input_source_exhausted = !Input::DataSource::IS_STREAMING; loop { // If the input buffer is empty, try to pull more data from the source before proceeding. // It's important that we do this _before_ reading from the buffer; any item returned @@ -257,6 +253,9 @@ impl StreamingRawReader { /// An input source--typically an implementation of either `AsRef<[u8]>` or `io::Read`--from which /// Ion can be read, paying the cost of buffering and I/O copies only when necessary. pub trait IonDataSource { + /// If `true`, the current contents of the buffer may not be the complete stream. + const IS_STREAMING: bool; + /// Returns a slice of all unread bytes that are currently available in the buffer. fn buffer(&self) -> &[u8]; @@ -268,9 +267,6 @@ pub trait IonDataSource { /// Marks `number_of_bytes` in the buffer as having been read. The caller is responsible for /// confirming that the buffer contains at least `number_of_bytes` bytes. fn consume(&mut self, number_of_bytes: usize); - - /// If `true`, the current contents of the buffer may not be the complete stream. - fn is_streaming(&self) -> bool; } /// A fixed slice of Ion data that does not grow; it wraps an implementation of `AsRef<[u8]>` such @@ -303,6 +299,8 @@ impl> IonSlice { } impl> IonDataSource for IonSlice { + const IS_STREAMING: bool = false; + #[inline] fn buffer(&self) -> &[u8] { // Return the input slice containing all of the as-of-yet unread bytes. @@ -327,11 +325,6 @@ impl> IonDataSource for IonSlice { self.buffer() ); } - - #[inline(always)] - fn is_streaming(&self) -> bool { - false - } } /// A buffered reader for types that don't implement AsRef<[u8]> @@ -377,6 +370,8 @@ impl IonStream { } impl IonDataSource for IonStream { + const IS_STREAMING: bool = true; + fn buffer(&self) -> &[u8] { &self.buffer[self.position..self.limit] } @@ -406,11 +401,6 @@ impl IonDataSource for IonStream { self.position += number_of_bytes; debug_assert!(self.position <= self.limit); } - - #[inline(always)] - fn is_streaming(&self) -> bool { - true - } } /// Types that can be used as a source of Ion data.