#[doc(hidden)]pub trait SizeHint {
// Required methods
fn lower_bound(&self) -> usize;
fn upper_bound(&self) -> Option<usize>;
// Provided method
final fn size_hint(&self) -> (usize, Option<usize>) { ... }
}core_io_internals)Expand description
Internal trait used to allow for specialization in Read::size_hint and
Iterator::size_hint.
All types implement this through a blanket default implementation returning
a hint of (0, None).
Implementors should only provide lower_bound and
upper_bound.
size_hint is provided as a final method to enforce
correctness.
Required Methods§
Sourcefn lower_bound(&self) -> usize
🔬This is a nightly-only experimental API. (core_io_internals)
fn lower_bound(&self) -> usize
core_io_internals)Returns a lower bound on the number of elements this container-like item
contains.
For example, an array [u8; 12] could return any value between 0 and
12 inclusively as a correct implementation.
Through specialization, all types implement this method returning a default
value of 0.
Implementations must ensure the returned value is less than or equal to the true element count.
Sourcefn upper_bound(&self) -> Option<usize>
🔬This is a nightly-only experimental API. (core_io_internals)
fn upper_bound(&self) -> Option<usize>
core_io_internals)Returns an upper bound on the number of elements this container-like item
contains if it can be determined, otherwise None.
Through specialization, all types implement this method returning a default
value of None.
Implementations must ensure the returned value is greater than or equal to the true element count.
Provided Methods§
Sourcefinal fn size_hint(&self) -> (usize, Option<usize>)
🔬This is a nightly-only experimental API. (core_io_internals)
final fn size_hint(&self) -> (usize, Option<usize>)
core_io_internals)Returns an estimate for the number of elements this container like type contains.
This is a final method, and is guaranteed to return
(self.lower_bound(), self.upper_bound()).
Without specialization, types implementing this trait will return (0, None).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".