#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct TableStatistics {
records: u64,
data_file_length: u64,
max_data_file_length: u64,
index_file_length: u64,
max_index_file_length: u64,
delete_length: u64,
auto_increment_value: u64,
deleted: u64,
mean_rec_length: u64,
create_time: i64,
check_time: u64,
update_time: u64,
block_size: u32,
}
impl TableStatistics {
#[must_use]
pub const fn new() -> Self {
Self {
records: 0,
data_file_length: 0,
max_data_file_length: 0,
index_file_length: 0,
max_index_file_length: 0,
delete_length: 0,
auto_increment_value: 0,
deleted: 0,
mean_rec_length: 0,
create_time: 0,
check_time: 0,
update_time: 0,
block_size: 0,
}
}
#[must_use]
pub const fn with_records(mut self, value: u64) -> Self {
self.records = value;
self
}
#[must_use]
pub const fn with_data_file_length(mut self, value: u64) -> Self {
self.data_file_length = value;
self
}
#[must_use]
pub const fn with_max_data_file_length(mut self, value: u64) -> Self {
self.max_data_file_length = value;
self
}
#[must_use]
pub const fn with_index_file_length(mut self, value: u64) -> Self {
self.index_file_length = value;
self
}
#[must_use]
pub const fn with_max_index_file_length(mut self, value: u64) -> Self {
self.max_index_file_length = value;
self
}
#[must_use]
pub const fn with_delete_length(mut self, value: u64) -> Self {
self.delete_length = value;
self
}
#[must_use]
pub const fn with_auto_increment_value(mut self, value: u64) -> Self {
self.auto_increment_value = value;
self
}
#[must_use]
pub const fn with_deleted(mut self, value: u64) -> Self {
self.deleted = value;
self
}
#[must_use]
pub const fn with_mean_rec_length(mut self, value: u64) -> Self {
self.mean_rec_length = value;
self
}
#[must_use]
pub const fn with_create_time(mut self, value: i64) -> Self {
self.create_time = value;
self
}
#[must_use]
pub const fn with_check_time(mut self, value: u64) -> Self {
self.check_time = value;
self
}
#[must_use]
pub const fn with_update_time(mut self, value: u64) -> Self {
self.update_time = value;
self
}
#[must_use]
pub const fn with_block_size(mut self, value: u32) -> Self {
self.block_size = value;
self
}
pub const fn records(&self) -> u64 {
self.records
}
pub const fn data_file_length(&self) -> u64 {
self.data_file_length
}
pub const fn max_data_file_length(&self) -> u64 {
self.max_data_file_length
}
pub const fn index_file_length(&self) -> u64 {
self.index_file_length
}
pub const fn max_index_file_length(&self) -> u64 {
self.max_index_file_length
}
pub const fn delete_length(&self) -> u64 {
self.delete_length
}
pub const fn auto_increment_value(&self) -> u64 {
self.auto_increment_value
}
pub const fn deleted(&self) -> u64 {
self.deleted
}
pub const fn mean_rec_length(&self) -> u64 {
self.mean_rec_length
}
pub const fn create_time(&self) -> i64 {
self.create_time
}
pub const fn check_time(&self) -> u64 {
self.check_time
}
pub const fn update_time(&self) -> u64 {
self.update_time
}
pub const fn block_size(&self) -> u32 {
self.block_size
}
}
impl Default for TableStatistics {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn new_zeros_every_field() {
let s = TableStatistics::new();
assert_eq!(s.records(), 0);
assert_eq!(s.data_file_length(), 0);
assert_eq!(s.block_size(), 0);
}
#[test]
fn builder_preserves_each_setter() {
let s = TableStatistics::new()
.with_records(100)
.with_data_file_length(4096)
.with_block_size(16);
assert_eq!(s.records(), 100);
assert_eq!(s.data_file_length(), 4096);
assert_eq!(s.block_size(), 16);
}
}