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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! `IVirtualResponse` and `VirtualResponse` (`Cache/IVirtualResponse.cs`,
//! `Cache/VirtualResponse.cs`).
use std::fmt;
/// The window of sorted items that a virtual change set holds (`IVirtualResponse`).
pub trait IVirtualResponse {
/// The number of items requested (`Size`).
fn size(&self) -> usize;
/// The index of the first item (`StartIndex`).
fn start_index(&self) -> usize;
/// The number of items of the whole collection (`TotalSize`).
fn total_size(&self) -> usize;
}
/// The window of sorted items that a virtual change set holds (`VirtualResponse`). Two responses
/// are equal when their parts are (`VirtualResponse.DefaultComparer`).
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct VirtualResponse {
size: usize,
start_index: usize,
total_size: usize,
}
impl VirtualResponse {
/// The window of `size` items from `start_index`, of `total_size` items in all
/// (`VirtualResponse(int size, int startIndex, int totalSize)`).
pub const fn new(size: usize, start_index: usize, total_size: usize) -> Self {
Self { size, start_index, total_size }
}
/// The number of items requested (`Size`).
pub const fn size(&self) -> usize {
self.size
}
/// The index of the first item (`StartIndex`).
pub const fn start_index(&self) -> usize {
self.start_index
}
/// The number of items of the whole collection (`TotalSize`).
pub const fn total_size(&self) -> usize {
self.total_size
}
}
impl IVirtualResponse for VirtualResponse {
fn size(&self) -> usize {
self.size
}
fn start_index(&self) -> usize {
self.start_index
}
fn total_size(&self) -> usize {
self.total_size
}
}
impl fmt::Display for VirtualResponse {
/// `ToString`.
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Size: {}, StartIndex: {}, TotalSize: {}", self.size, self.start_index, self.total_size)
}
}