Skip to content

Commit

Permalink
Merge pull request #152 from rust-embedded-community/simplify-examples
Browse files Browse the repository at this point in the history
Create a VolumeManager type alias
  • Loading branch information
thejpster authored Oct 19, 2024
2 parents c67d6ca + c89b01b commit 1b9fa5c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 26 deletions.
7 changes: 4 additions & 3 deletions examples/append_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ use linux::*;

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

use embedded_sdmmc::{Error, Mode, VolumeIdx, VolumeManager};
use embedded_sdmmc::{Error, Mode, VolumeIdx};

type VolumeManager = embedded_sdmmc::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;

fn main() -> Result<(), embedded_sdmmc::Error<std::io::Error>> {
env_logger::init();
let mut args = std::env::args().skip(1);
let filename = args.next().unwrap_or_else(|| "/dev/mmcblk0".into());
let print_blocks = args.find(|x| x == "-v").map(|_| true).unwrap_or(false);
let lbd = LinuxBlockDevice::new(filename, print_blocks).map_err(Error::DeviceError)?;
let volume_mgr: VolumeManager<LinuxBlockDevice, Clock, 8, 8, 4> =
VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
let volume_mgr: VolumeManager = VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
let volume = volume_mgr.open_volume(VolumeIdx(0))?;
let root_dir = volume.open_root_dir()?;
println!("\nCreating file {}...", FILE_TO_APPEND);
Expand Down
7 changes: 4 additions & 3 deletions examples/big_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ extern crate embedded_sdmmc;
mod linux;
use linux::*;

use embedded_sdmmc::{Error, VolumeManager};
use embedded_sdmmc::Error;

type VolumeManager = embedded_sdmmc::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;

fn main() -> Result<(), embedded_sdmmc::Error<std::io::Error>> {
env_logger::init();
let mut args = std::env::args().skip(1);
let filename = args.next().unwrap_or_else(|| "/dev/mmcblk0".into());
let print_blocks = args.find(|x| x == "-v").map(|_| true).unwrap_or(false);
let lbd = LinuxBlockDevice::new(filename, print_blocks).map_err(Error::DeviceError)?;
let volume_mgr: VolumeManager<LinuxBlockDevice, Clock, 8, 8, 4> =
VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
let volume_mgr: VolumeManager = VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
let volume = volume_mgr
.open_volume(embedded_sdmmc::VolumeIdx(1))
.unwrap();
Expand Down
7 changes: 4 additions & 3 deletions examples/create_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ use linux::*;

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

use embedded_sdmmc::{Error, Mode, VolumeIdx, VolumeManager};
use embedded_sdmmc::{Error, Mode, VolumeIdx};

type VolumeManager = embedded_sdmmc::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;

fn main() -> Result<(), embedded_sdmmc::Error<std::io::Error>> {
env_logger::init();
let mut args = std::env::args().skip(1);
let filename = args.next().unwrap_or_else(|| "/dev/mmcblk0".into());
let print_blocks = args.find(|x| x == "-v").map(|_| true).unwrap_or(false);
let lbd = LinuxBlockDevice::new(filename, print_blocks).map_err(Error::DeviceError)?;
let volume_mgr: VolumeManager<LinuxBlockDevice, Clock, 8, 8, 4> =
VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
let volume_mgr: VolumeManager = VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
let volume = volume_mgr.open_volume(VolumeIdx(0))?;
let root_dir = volume.open_root_dir()?;
println!("\nCreating file {}...", FILE_TO_CREATE);
Expand Down
7 changes: 4 additions & 3 deletions examples/delete_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ use linux::*;

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

use embedded_sdmmc::{Error, VolumeIdx, VolumeManager};
use embedded_sdmmc::{Error, VolumeIdx};

type VolumeManager = embedded_sdmmc::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;

fn main() -> Result<(), embedded_sdmmc::Error<std::io::Error>> {
env_logger::init();
let mut args = std::env::args().skip(1);
let filename = args.next().unwrap_or_else(|| "/dev/mmcblk0".into());
let print_blocks = args.find(|x| x == "-v").map(|_| true).unwrap_or(false);
let lbd = LinuxBlockDevice::new(filename, print_blocks).map_err(Error::DeviceError)?;
let volume_mgr: VolumeManager<LinuxBlockDevice, Clock, 8, 8, 4> =
VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
let volume_mgr: VolumeManager = VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
let volume = volume_mgr.open_volume(VolumeIdx(0))?;
let root_dir = volume.open_root_dir()?;
println!("Deleting file {}...", FILE_TO_DELETE);
Expand Down
20 changes: 9 additions & 11 deletions examples/list_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,24 @@
//! $ cargo run --example list_dir -- ./disk.img
//! ```

extern crate embedded_sdmmc;

mod linux;
use linux::*;

use embedded_sdmmc::{Directory, VolumeIdx, VolumeManager};
use embedded_sdmmc::{ShortFileName, VolumeIdx};

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

type Directory<'a> = embedded_sdmmc::Directory<'a, LinuxBlockDevice, Clock, 8, 4, 4>;
type VolumeManager = embedded_sdmmc::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;

fn main() -> Result<(), Error> {
env_logger::init();
let mut args = std::env::args().skip(1);
let filename = args.next().unwrap_or_else(|| "/dev/mmcblk0".into());
let print_blocks = args.find(|x| x == "-v").map(|_| true).unwrap_or(false);

let lbd = LinuxBlockDevice::new(filename, print_blocks).map_err(Error::DeviceError)?;
let volume_mgr: VolumeManager<LinuxBlockDevice, Clock, 8, 8, 4> =
VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
let volume_mgr: VolumeManager = VolumeManager::new_with_limits(lbd, Clock, 0xAA00_0000);
let volume = volume_mgr.open_volume(VolumeIdx(0))?;
let root_dir = volume.open_root_dir()?;
list_dir(root_dir, "/")?;
Expand All @@ -58,10 +59,7 @@ fn main() -> Result<(), Error> {
/// Recursively print a directory listing for the open directory given.
///
/// The path is for display purposes only.
fn list_dir(
directory: Directory<LinuxBlockDevice, Clock, 8, 8, 4>,
path: &str,
) -> Result<(), Error> {
fn list_dir(directory: Directory<'_>, path: &str) -> Result<(), Error> {
println!("Listing {}", path);
let mut children = Vec::new();
directory.iterate_dir(|entry| {
Expand All @@ -77,8 +75,8 @@ fn list_dir(
}
);
if entry.attributes.is_directory()
&& entry.name != embedded_sdmmc::ShortFileName::parent_dir()
&& entry.name != embedded_sdmmc::ShortFileName::this_dir()
&& entry.name != ShortFileName::parent_dir()
&& entry.name != ShortFileName::this_dir()
{
children.push(entry.name.clone());
}
Expand Down
7 changes: 4 additions & 3 deletions examples/read_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ use linux::*;

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

use embedded_sdmmc::{Error, Mode, VolumeIdx, VolumeManager};
use embedded_sdmmc::{Error, Mode, VolumeIdx};

type VolumeManager = embedded_sdmmc::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;

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

0 comments on commit 1b9fa5c

Please sign in to comment.