Skip to content

Commit 1b9fa5c

Browse files
authored
Merge pull request #152 from rust-embedded-community/simplify-examples
Create a VolumeManager type alias
2 parents c67d6ca + c89b01b commit 1b9fa5c

File tree

6 files changed

+29
-26
lines changed

6 files changed

+29
-26
lines changed

examples/append_file.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ use linux::*;
2222

2323
const FILE_TO_APPEND: &str = "README.TXT";
2424

25-
use embedded_sdmmc::{Error, Mode, VolumeIdx, VolumeManager};
25+
use embedded_sdmmc::{Error, Mode, VolumeIdx};
26+
27+
type VolumeManager = embedded_sdmmc::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;
2628

2729
fn main() -> Result<(), embedded_sdmmc::Error<std::io::Error>> {
2830
env_logger::init();
2931
let mut args = std::env::args().skip(1);
3032
let filename = args.next().unwrap_or_else(|| "/dev/mmcblk0".into());
3133
let print_blocks = args.find(|x| x == "-v").map(|_| true).unwrap_or(false);
3234
let lbd = LinuxBlockDevice::new(filename, print_blocks).map_err(Error::DeviceError)?;
33-
let volume_mgr: VolumeManager<LinuxBlockDevice, Clock, 8, 8, 4> =
34-
VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
35+
let volume_mgr: VolumeManager = VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
3536
let volume = volume_mgr.open_volume(VolumeIdx(0))?;
3637
let root_dir = volume.open_root_dir()?;
3738
println!("\nCreating file {}...", FILE_TO_APPEND);

examples/big_dir.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ extern crate embedded_sdmmc;
33
mod linux;
44
use linux::*;
55

6-
use embedded_sdmmc::{Error, VolumeManager};
6+
use embedded_sdmmc::Error;
7+
8+
type VolumeManager = embedded_sdmmc::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;
79

810
fn main() -> Result<(), embedded_sdmmc::Error<std::io::Error>> {
911
env_logger::init();
1012
let mut args = std::env::args().skip(1);
1113
let filename = args.next().unwrap_or_else(|| "/dev/mmcblk0".into());
1214
let print_blocks = args.find(|x| x == "-v").map(|_| true).unwrap_or(false);
1315
let lbd = LinuxBlockDevice::new(filename, print_blocks).map_err(Error::DeviceError)?;
14-
let volume_mgr: VolumeManager<LinuxBlockDevice, Clock, 8, 8, 4> =
15-
VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
16+
let volume_mgr: VolumeManager = VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
1617
let volume = volume_mgr
1718
.open_volume(embedded_sdmmc::VolumeIdx(1))
1819
.unwrap();

examples/create_file.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ use linux::*;
2222

2323
const FILE_TO_CREATE: &str = "CREATE.TXT";
2424

25-
use embedded_sdmmc::{Error, Mode, VolumeIdx, VolumeManager};
25+
use embedded_sdmmc::{Error, Mode, VolumeIdx};
26+
27+
type VolumeManager = embedded_sdmmc::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;
2628

2729
fn main() -> Result<(), embedded_sdmmc::Error<std::io::Error>> {
2830
env_logger::init();
2931
let mut args = std::env::args().skip(1);
3032
let filename = args.next().unwrap_or_else(|| "/dev/mmcblk0".into());
3133
let print_blocks = args.find(|x| x == "-v").map(|_| true).unwrap_or(false);
3234
let lbd = LinuxBlockDevice::new(filename, print_blocks).map_err(Error::DeviceError)?;
33-
let volume_mgr: VolumeManager<LinuxBlockDevice, Clock, 8, 8, 4> =
34-
VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
35+
let volume_mgr: VolumeManager = VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
3536
let volume = volume_mgr.open_volume(VolumeIdx(0))?;
3637
let root_dir = volume.open_root_dir()?;
3738
println!("\nCreating file {}...", FILE_TO_CREATE);

examples/delete_file.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ use linux::*;
2525

2626
const FILE_TO_DELETE: &str = "README.TXT";
2727

28-
use embedded_sdmmc::{Error, VolumeIdx, VolumeManager};
28+
use embedded_sdmmc::{Error, VolumeIdx};
29+
30+
type VolumeManager = embedded_sdmmc::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;
2931

3032
fn main() -> Result<(), embedded_sdmmc::Error<std::io::Error>> {
3133
env_logger::init();
3234
let mut args = std::env::args().skip(1);
3335
let filename = args.next().unwrap_or_else(|| "/dev/mmcblk0".into());
3436
let print_blocks = args.find(|x| x == "-v").map(|_| true).unwrap_or(false);
3537
let lbd = LinuxBlockDevice::new(filename, print_blocks).map_err(Error::DeviceError)?;
36-
let volume_mgr: VolumeManager<LinuxBlockDevice, Clock, 8, 8, 4> =
37-
VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
38+
let volume_mgr: VolumeManager = VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
3839
let volume = volume_mgr.open_volume(VolumeIdx(0))?;
3940
let root_dir = volume.open_root_dir()?;
4041
println!("Deleting file {}...", FILE_TO_DELETE);

examples/list_dir.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,24 @@
3232
//! $ cargo run --example list_dir -- ./disk.img
3333
//! ```
3434
35-
extern crate embedded_sdmmc;
36-
3735
mod linux;
3836
use linux::*;
3937

40-
use embedded_sdmmc::{Directory, VolumeIdx, VolumeManager};
38+
use embedded_sdmmc::{ShortFileName, VolumeIdx};
4139

4240
type Error = embedded_sdmmc::Error<std::io::Error>;
4341

42+
type Directory<'a> = embedded_sdmmc::Directory<'a, LinuxBlockDevice, Clock, 8, 4, 4>;
43+
type VolumeManager = embedded_sdmmc::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;
44+
4445
fn main() -> Result<(), Error> {
4546
env_logger::init();
4647
let mut args = std::env::args().skip(1);
4748
let filename = args.next().unwrap_or_else(|| "/dev/mmcblk0".into());
4849
let print_blocks = args.find(|x| x == "-v").map(|_| true).unwrap_or(false);
50+
4951
let lbd = LinuxBlockDevice::new(filename, print_blocks).map_err(Error::DeviceError)?;
50-
let volume_mgr: VolumeManager<LinuxBlockDevice, Clock, 8, 8, 4> =
51-
VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
52+
let volume_mgr: VolumeManager = VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
5253
let volume = volume_mgr.open_volume(VolumeIdx(0))?;
5354
let root_dir = volume.open_root_dir()?;
5455
list_dir(root_dir, "/")?;
@@ -58,10 +59,7 @@ fn main() -> Result<(), Error> {
5859
/// Recursively print a directory listing for the open directory given.
5960
///
6061
/// The path is for display purposes only.
61-
fn list_dir(
62-
directory: Directory<LinuxBlockDevice, Clock, 8, 8, 4>,
63-
path: &str,
64-
) -> Result<(), Error> {
62+
fn list_dir(directory: Directory<'_>, path: &str) -> Result<(), Error> {
6563
println!("Listing {}", path);
6664
let mut children = Vec::new();
6765
directory.iterate_dir(|entry| {
@@ -77,8 +75,8 @@ fn list_dir(
7775
}
7876
);
7977
if entry.attributes.is_directory()
80-
&& entry.name != embedded_sdmmc::ShortFileName::parent_dir()
81-
&& entry.name != embedded_sdmmc::ShortFileName::this_dir()
78+
&& entry.name != ShortFileName::parent_dir()
79+
&& entry.name != ShortFileName::this_dir()
8280
{
8381
children.push(entry.name.clone());
8482
}

examples/read_file.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,17 @@ use linux::*;
3939

4040
const FILE_TO_READ: &str = "README.TXT";
4141

42-
use embedded_sdmmc::{Error, Mode, VolumeIdx, VolumeManager};
42+
use embedded_sdmmc::{Error, Mode, VolumeIdx};
43+
44+
type VolumeManager = embedded_sdmmc::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;
4345

4446
fn main() -> Result<(), embedded_sdmmc::Error<std::io::Error>> {
4547
env_logger::init();
4648
let mut args = std::env::args().skip(1);
4749
let filename = args.next().unwrap_or_else(|| "/dev/mmcblk0".into());
4850
let print_blocks = args.find(|x| x == "-v").map(|_| true).unwrap_or(false);
4951
let lbd = LinuxBlockDevice::new(filename, print_blocks).map_err(Error::DeviceError)?;
50-
let volume_mgr: VolumeManager<LinuxBlockDevice, Clock, 8, 8, 4> =
51-
VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
52+
let volume_mgr: VolumeManager = VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
5253
let volume = volume_mgr.open_volume(VolumeIdx(0))?;
5354
let root_dir = volume.open_root_dir()?;
5455
println!("\nReading file {}...", FILE_TO_READ);

0 commit comments

Comments
 (0)