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 operationsDataError- Errors related to data management and processingRenderError- Errors during rendering and drawing operationsLayoutError- Errors in chart layout and positioningAnimationError- 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::Displayinstead ofstd::fmt::Display - Optional
std::error::Errorimplementation whenstdfeature is enabled
§Memory Efficiency
Error types are designed for minimal memory usage:
- All error variants are
Copytypes - No dynamic string allocation
- Efficient error code representation
Structs§
- Error
Context - Error context information for better debugging
Enums§
- Animation
Error - Error type for animation operations.
- Chart
Error - Main error type for chart operations.
- Data
Error - Error type for data operations.
- Data
Error Kind - Data error kinds for backwards compatibility
- Layout
Error - Error type for layout operations.
- Render
Error - Error type for rendering operations.
Type Aliases§
- Animation
Result - Result type for animation operations
- Chart
Result - Result type for chart operations
- Data
Result - Result type for data operations
- Layout
Result - Result type for layout operations
- Render
Result - Result type for rendering operations