io_block/
file.rs

1use super::*;
2use core::ops::{Deref, DerefMut};
3
4/**
5 * Wrap some type T in a block container
6 */
7pub struct BlockFile<T> {
8    file: T,
9    block_sz: u64,
10    block_ct: u64,
11}
12
13impl<T> Deref for BlockFile<T> {
14    type Target = T;
15    fn deref(&self) -> &<Self as Deref>::Target {
16        &self.file
17    }
18}
19
20impl<T> DerefMut for BlockFile<T> {
21    fn deref_mut(&mut self) -> &mut Self::Target {
22        &mut self.file
23    }
24}
25
26/*
27impl<T> Into<T> for BlockFile<T> {
28    fn into(self) -> T {
29        self.file
30    }
31}
32*/
33
34impl<T> BlockSize for BlockFile<T> {
35    fn block_size_logical(&self) -> Result<u64> {
36        Ok(self.block_sz)
37    }
38
39    fn block_count(&self) -> Result<u64> {
40        Ok(self.block_ct)
41    }
42
43    fn block_size_physical(&self) -> Result<u64> {
44        self.block_size_logical()
45    }
46}
47
48impl<T> BlockFile<T> {
49    pub fn new(file: T, block_sz: u64, block_ct: u64) -> BlockFile<T> {
50        BlockFile {
51            file,
52            block_sz,
53            block_ct,
54        }
55    }
56}
57
58#[cfg(test)]
59mod tests {
60    #[test]
61    fn blk_file() {}
62}