1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/// [`Records`] extension which guarantees the amount of rows.
///
/// [`Records`]: crate::records::Records
pub trait ExactRecords {
    /// Returns an exact amount of rows in records.
    ///
    /// It must be guaranteed that an iterator will yield this amount.
    fn count_rows(&self) -> usize;
}

impl<T> ExactRecords for &T
where
    T: ExactRecords,
{
    fn count_rows(&self) -> usize {
        T::count_rows(self)
    }
}

#[cfg(feature = "std")]
impl<T> ExactRecords for Vec<T> {
    fn count_rows(&self) -> usize {
        self.len()
    }
}

impl<T> ExactRecords for [T] {
    fn count_rows(&self) -> usize {
        self.len()
    }
}