fuchsia_fatfs/
types.rs

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
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

//! These type declarations simply exist to reduce the amount of boilerplate in the other parts of
//! this crate.

use fatfs::{DefaultTimeProvider, LossyOemCpConverter, ReadWriteSeek};

pub trait Disk: ReadWriteSeek + Send {
    /// Returns true if the underlying block device for this disk is still present.
    fn is_present(&self) -> bool;
}

// Default implementation, used for tests.
impl Disk for std::io::Cursor<Vec<u8>> {
    fn is_present(&self) -> bool {
        true
    }
}

impl Disk for block_client::Cache {
    fn is_present(&self) -> bool {
        self.device().is_connected()
    }
}

pub type FileSystem = fatfs::FileSystem<Box<dyn Disk>, DefaultTimeProvider, LossyOemCpConverter>;
pub type Dir<'a> = fatfs::Dir<'a, Box<dyn Disk>, DefaultTimeProvider, LossyOemCpConverter>;
pub type DirEntry<'a> =
    fatfs::DirEntry<'a, Box<dyn Disk>, DefaultTimeProvider, LossyOemCpConverter>;
pub type File<'a> = fatfs::File<'a, Box<dyn Disk>, DefaultTimeProvider, LossyOemCpConverter>;