From 0b5b04aca613bb44dc7498711585b92d5edf146e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Harabie=C5=84?= Date: Wed, 6 Jun 2018 14:01:19 +0200 Subject: [PATCH] Make FileSystemStats struct fields non-public and add getters This way new fields can be added later without losing backward compatibility. --- src/fs.rs | 20 +++++++++++++++++--- tests/read.rs | 18 +++++++++--------- tests/write.rs | 2 +- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/fs.rs b/src/fs.rs index 44ae969..ea3c39d 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -311,11 +311,25 @@ impl FsOptions { #[derive(Debug, Clone, Copy)] pub struct FileSystemStats { /// Cluster size in bytes - pub cluster_size: u32, + cluster_size: u32, /// Number of total clusters in filesystem usable for file allocation - pub total_clusters: u32, + total_clusters: u32, /// Number of free clusters - pub free_clusters: u32, + free_clusters: u32, +} + +impl FileSystemStats { + pub fn cluster_size(&self) -> u32 { + self.cluster_size + } + + pub fn total_clusters(&self) -> u32 { + self.total_clusters + } + + pub fn free_clusters(&self) -> u32 { + self.free_clusters + } } pub(crate) type FileSystemRef<'a, 'b> = &'a FileSystem<'b>; diff --git a/tests/read.rs b/tests/read.rs index 1df4402..7640aa8 100644 --- a/tests/read.rs +++ b/tests/read.rs @@ -218,9 +218,9 @@ fn test_status_flags_fat32() { fn test_stats_fat12() { call_with_fs(&|fs| { let stats = fs.stats().unwrap(); - assert_eq!(stats.cluster_size, 512); - assert_eq!(stats.total_clusters, 1955); // 1000 * 1024 / 512 = 2000 - assert_eq!(stats.free_clusters, 1920); + assert_eq!(stats.cluster_size(), 512); + assert_eq!(stats.total_clusters(), 1955); // 1000 * 1024 / 512 = 2000 + assert_eq!(stats.free_clusters(), 1920); }, FAT12_IMG) } @@ -228,9 +228,9 @@ fn test_stats_fat12() { fn test_stats_fat16() { call_with_fs(&|fs| { let stats = fs.stats().unwrap(); - assert_eq!(stats.cluster_size, 512); - assert_eq!(stats.total_clusters, 4927); // 2500 * 1024 / 512 = 5000 - assert_eq!(stats.free_clusters, 4892); + assert_eq!(stats.cluster_size(), 512); + assert_eq!(stats.total_clusters(), 4927); // 2500 * 1024 / 512 = 5000 + assert_eq!(stats.free_clusters(), 4892); }, FAT16_IMG) } @@ -238,8 +238,8 @@ fn test_stats_fat16() { fn test_stats_fat32() { call_with_fs(&|fs| { let stats = fs.stats().unwrap(); - assert_eq!(stats.cluster_size, 512); - assert_eq!(stats.total_clusters, 66922); // 34000 * 1024 / 512 = 68000 - assert_eq!(stats.free_clusters, 66886); + assert_eq!(stats.cluster_size(), 512); + assert_eq!(stats.total_clusters(), 66922); // 34000 * 1024 / 512 = 68000 + assert_eq!(stats.free_clusters(), 66886); }, FAT32_IMG) } diff --git a/tests/write.rs b/tests/write.rs index 3d5c992..8fe58fe 100644 --- a/tests/write.rs +++ b/tests/write.rs @@ -252,7 +252,7 @@ fn test_rename_file(fs: FileSystem) { assert_eq!(str::from_utf8(&buf).unwrap(), TEST_STR2); let new_stats = fs.stats().unwrap(); - assert_eq!(new_stats.free_clusters, stats.free_clusters); + assert_eq!(new_stats.free_clusters(), stats.free_clusters()); } #[test]