pub trait DeltaEncoderExt: Iterator{
// Provided method
fn deltas(self) -> DeltaEncoderIter<Self> ⓘ
where Self: Sized { ... }
}
Provided Methods§
Sourcefn deltas(self) -> DeltaEncoderIter<Self> ⓘwhere
Self: Sized,
fn deltas(self) -> DeltaEncoderIter<Self> ⓘwhere
Self: Sized,
Construct a delta-encoded iterator from an iterator.
The first element of the iterator is used as the starting point for the delta-encoding.
Note that unlike the [DeltaEncoder.encode
] method, this method will panic if the delta is too large.
§Example
use delta_encoding::DeltaEncoderExt;
// Consuming original data into a delta-encoded iterator.
let mut encoded: Vec<i64> = vec![1, 2, 5, 4, 2].into_iter().deltas().collect();
assert_eq!(encoded, vec![1, 1, 3, -1, -2]);
// Non-consuming original data, but avoiding the allocation of a new vector.
let mut encoded: Vec<i64> = vec![1, 2, 5, 4, 2].iter().copied().deltas().collect();
assert_eq!(encoded, vec![1, 1, 3, -1, -2]);