Module error

Module error 

Source
Expand description

Error types and result handling for the embedded graphics chart library.

This module provides comprehensive error handling for all chart operations while maintaining compatibility with both std and no_std environments. All error types implement the necessary traits for proper error propagation and debugging.

§Error Categories

The library uses a hierarchical error system with specific error types for different operation categories:

  • ChartError - Main error type for high-level chart operations
  • DataError - Errors related to data management and processing
  • RenderError - Errors during rendering and drawing operations
  • LayoutError - Errors in chart layout and positioning
  • AnimationError - Errors in animation system (feature-gated)

§Error Handling Patterns

§Basic Error Handling

use embedded_charts::prelude::*;
use embedded_graphics::pixelcolor::Rgb565;

let mut data: StaticDataSeries<Point2D, 256> = StaticDataSeries::new();
match data.push(Point2D::new(0.0, 10.0)) {
    Ok(()) => println!("Data added successfully"),
    Err(DataError::BufferFull { .. }) => println!("Data series is full"),
    Err(e) => println!("Other error: {}", e),
}

§Using Result Types

use embedded_charts::prelude::*;
use embedded_charts::error::ChartResult;

fn create_chart() -> ChartResult<LineChart<embedded_graphics::pixelcolor::Rgb565>> {
    LineChart::builder()
        .line_color(embedded_graphics::pixelcolor::Rgb565::BLUE)
        .build()
}

§Error Propagation

use embedded_charts::prelude::*;
use embedded_charts::error::{ChartResult, DataError};

fn process_data() -> ChartResult<()> {
    let mut data: StaticDataSeries<Point2D, 256> = StaticDataSeries::new();
    data.push(Point2D::new(0.0, 10.0))?; // Automatically converts DataError to ChartError
    Ok(())
}

§no_std Compatibility

All error types are designed to work in no_std environments:

  • No heap allocation for error messages
  • Implement core::fmt::Display instead of std::fmt::Display
  • Optional std::error::Error implementation when std feature is enabled

§Memory Efficiency

Error types are designed for minimal memory usage:

  • All error variants are Copy types
  • No dynamic string allocation
  • Efficient error code representation

Structs§

ErrorContext
Error context information for better debugging

Enums§

AnimationError
Error type for animation operations.
ChartError
Main error type for chart operations.
DataError
Error type for data operations.
DataErrorKind
Data error kinds for backwards compatibility
LayoutError
Error type for layout operations.
RenderError
Error type for rendering operations.

Type Aliases§

AnimationResult
Result type for animation operations
ChartResult
Result type for chart operations
DataResult
Result type for data operations
LayoutResult
Result type for layout operations
RenderResult
Result type for rendering operations