Skip to main content

Crate littlefs_rust

Crate littlefs_rust 

Source
Expand description

Safe Rust API for the LittleFS embedded filesystem.

Built on littlefs-rust-core, a function-by-function Rust port of the C littlefs. No C toolchain required.

§Quick start

use littlefs_rust::{Config, Filesystem, RamStorage};

let mut storage = RamStorage::new(512, 128);
let config = Config::new(512, 128);

Filesystem::format(&mut storage, &config).unwrap();
let fs = Filesystem::mount(storage, config).map_err(|(e, _)| e).unwrap();

fs.write_file("/hello.txt", b"Hello, littlefs!").unwrap();
let data = fs.read_to_vec("/hello.txt").unwrap();
assert_eq!(data, b"Hello, littlefs!");

fs.unmount().unwrap();

§Architecture

The crate uses interior mutability (RefCell) so that Filesystem methods take &self. Each operation borrows the internal state only for the duration of one core call, then releases it. This enables multiple open files, interleaved file and directory operations, and reading files while iterating directories — all without conflict.

File and ReadDir hold a shared reference to the Filesystem and implement Drop for RAII close.

Structs§

Config
Filesystem configuration.
DirEntry
A single entry from a directory listing.
File
An open file handle.
Filesystem
A mounted LittleFS filesystem.
Metadata
Metadata for a file or directory, as returned by Filesystem::stat.
OpenFlags
Flags for opening a file. Combine with |.
RamStorage
In-memory block device for testing and examples.
ReadDir
An open directory iterator.

Enums§

Error
LittleFS operation error.
FileType
Type of a filesystem entry.
SeekFrom
Position for File::seek.

Traits§

Storage
Block device storage backend.