Skip to main content

Crate hadris_io

Crate hadris_io 

Source
Expand description

§Hadris IO

Portable I/O trait abstractions for the Hadris filesystem crates.

This crate provides Read, Write, and Seek traits that work in both std and no_std environments. When the std feature is enabled, the traits re-export directly from std::io. In no_std mode, minimal custom trait definitions are provided with the same API surface.

§Feature Flags

FeatureDefaultDescription
stdyesStandard library support (implies sync)
syncyesSynchronous I/O traits
asyncnoAsynchronous I/O traits (uses async fn in trait)

§Quick Start

use hadris_io::{Cursor, SeekFrom, Read, Seek};

let data = [0x48, 0x44, 0x52, 0x53]; // "HDRS"
let mut cursor = Cursor::new(&data);

let mut buf = [0u8; 2];
cursor.read_exact(&mut buf).unwrap();
assert_eq!(&buf, b"HD");

cursor.seek(SeekFrom::Start(0)).unwrap();
cursor.read_exact(&mut buf).unwrap();
assert_eq!(&buf, b"HD");

§Cursor

The Cursor type wraps a byte slice and provides both Read and Seek implementations, useful for in-memory parsing:

use hadris_io::Cursor;

let data = b"Hello, Hadris!";
let mut cursor = Cursor::new(data);
assert_eq!(cursor.position(), 0);
cursor.set_position(7);
assert_eq!(cursor.position(), 7);

§Extension Traits

The ReadExt trait adds structured reading via bytemuck:

use hadris_io::{Cursor, ReadExt};

let bytes = 0x1234u16.to_ne_bytes();
let mut cursor = Cursor::new(&bytes);
let value: u16 = cursor.read_struct().unwrap();
assert_eq!(value, 0x1234);

Re-exports§

pub use sync::*;

Modules§

sync
Synchronous I/O traits.

Macros§

try_io_result_option
Helper macro: short-circuit an Err by returning Some(Err(..)).

Structs§

Cursor
A no-std compatible Cursor for reading from byte slices.
Path
Re-export std path types when std is available. A slice of a path (akin to str).
PathBuf
Re-export std path types when std is available. An owned, mutable path (akin to String).

Enums§

Error
An error produced either by an underlying I/O object or by a Hadris helper.
ErrorKind
Portable error classification. This is a superset of embedded_io::ErrorKind and retains the std::io conditions Hadris needs for helper operations.
SeekFrom
Portable seek position, convertible to and from std::io::SeekFrom. Enumeration of possible methods to seek within an I/O object.

Traits§

IoError
Error implemented by portable underlying I/O sources.

Type Aliases§

Result
Result returned by Hadris helpers and filesystem operations.