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
use core::ops::{Deref,DerefMut};
use super::*;

/**
 * Wrap some type T in a block container
 */
pub struct BlockFile<T> {
    file: T,
    block_sz: u64,
    block_ct: u64,
}

impl<T> Deref for BlockFile<T> {
    type Target = T;
    fn deref(&self) -> &<Self as Deref>::Target {
        &self.file
    }
}

impl<T> DerefMut for BlockFile<T> {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.file
    }
}

/*
impl<T> Into<T> for BlockFile<T> {
    fn into(self) -> T {
        self.file
    }
}
*/

impl<T> BlockSize for BlockFile<T> {
    fn block_size_logical(&self) -> Result<u64> {
        Ok(self.block_sz)
    }

    fn block_count(&self) -> Result<u64> {
        Ok(self.block_ct)
    }
}

impl<T> BlockFile<T> {
    pub fn new(file: T, block_sz: u64, block_ct: u64) -> BlockFile<T> {
        BlockFile {
            file: file,
            block_sz: block_sz,
            block_ct: block_ct,
        }
    }
}

#[cfg(test)]
mod tests {
    #[test]
    fn blk_file() {
    }
}