Implementations

Relevant source files

This document provides an overview of the concrete implementations of I/O traits provided by the axio crate. These implementations offer ready-to-use functionality for common I/O operations in no_std environments. For detailed information about the core I/O traits themselves, see Core I/O Traits. For in-depth coverage of specific implementation categories, see Buffered I/O and Basic Type Implementations.

The axio crate provides two main categories of implementations: basic type implementations for fundamental Rust types, and buffered I/O implementations that add performance optimizations. These implementations are designed to work seamlessly in no_std environments while maintaining compatibility with std::io patterns.

Implementation Categories

The axio crate organizes its implementations into distinct categories based on functionality and feature requirements:

CategoryTypesTraits ImplementedFeature Requirements
Basic Types&[u8]ReadNone
Buffered I/OBufReaderRead,BufReadNone for core,allocfor enhanced methods

Implementation Architecture

flowchart TD
subgraph subGraph3["Source Files"]
    ImplsFile["src/impls.rs"]
    BufferedMod["src/buffered/mod.rs"]
    BufReaderFile["src/buffered/bufreader.rs"]
end
subgraph subGraph2["Buffered Implementations"]
    BufReaderImpl["BufReader impl Read"]
    BufReaderBufImpl["BufReader impl BufRead"]
end
subgraph subGraph1["Basic Implementations"]
    SliceImpl["&[u8] impl Read"]
end
subgraph subGraph0["Trait Definitions"]
    ReadTrait["Read trait"]
    WriteTrait["Write trait"]
    SeekTrait["Seek trait"]
    BufReadTrait["BufRead trait"]
end

BufReadTrait --> BufReaderBufImpl
BufReaderFile --> BufReaderBufImpl
BufReaderFile --> BufReaderImpl
BufferedMod --> BufReaderBufImpl
BufferedMod --> BufReaderImpl
ImplsFile --> SliceImpl
ReadTrait --> BufReaderImpl
ReadTrait --> SliceImpl

Sources: src/impls.rs(L1 - L54)  src/buffered/mod.rs(L1 - L4) 

Feature-Gated Implementation Matrix

Different implementations provide varying levels of functionality depending on enabled cargo features:

flowchart TD
subgraph Implementations["Implementations"]
    SliceRead["&[u8] Read impl"]
    BufReaderRead["BufReader Read impl"]
end
subgraph subGraph1["alloc Feature"]
    AllocMethods["Allocation Methodsread_to_end()read_to_string()"]
end
subgraph subGraph0["Default Features"]
    CoreMethods["Core Methodsread()read_exact()"]
end

AllocMethods --> BufReaderRead
AllocMethods --> SliceRead
CoreMethods --> BufReaderRead
CoreMethods --> SliceRead

Sources: src/impls.rs(L47 - L53) 

Implementation Details Overview

Basic Type Implementations

The &[u8] implementation in src/impls.rs provides a fundamental building block for reading from byte slices. This implementation includes performance optimizations and careful memory handling:

  • Single-byte optimization: Special handling for single-byte reads to avoid memcpy overhead
  • Exact reading: read_exact() method with proper error handling for insufficient data
  • Feature-gated extensions: read_to_end() method available only with alloc feature

The implementation uses axerrno::ax_err! macro for consistent error reporting and advances the slice pointer after each read operation.

Buffered I/O Module Structure

The buffered I/O implementations are organized through a module hierarchy:

flowchart TD
subgraph subGraph0["Public API"]
    BufReaderType["BufReader type"]
    ReadImpl["Read trait impl"]
    BufReadImpl["BufRead trait impl"]
end
BufferedMod["src/buffered/mod.rs"]
BufReaderMod["src/buffered/bufreader.rs"]
BufReaderExport["BufReader export"]
BufReaderImpl["BufReader implementation"]

BufReaderExport --> BufReaderType
BufReaderImpl --> BufReadImpl
BufReaderImpl --> ReadImpl
BufReaderMod --> BufReaderImpl
BufferedMod --> BufReaderExport

Sources: src/buffered/mod.rs(L1 - L4) 

Implementation Characteristics

All implementations in axio share common design principles:

  • no_std compatibility: No reliance on standard library components
  • Zero-copy where possible: Efficient memory usage patterns
  • Consistent error handling: Integration with axerrno error system
  • Feature-aware compilation: Conditional compilation based on cargo features

The implementations maintain API compatibility with std::io counterparts while providing the flexibility needed for resource-constrained environments.

Sources: src/impls.rs(L1 - L54)  src/buffered/mod.rs(L1 - L4)