pub trait Exportable {
// Required method
fn export(&self, config: &ExportConfig) -> Result<Vec<u8>, String>;
// Provided method
fn export_png(&self) -> Result<Vec<u8>, String> { ... }
}Expand description
Trait for implementing chart export functionality
Implement this trait on your chart widgets to enable export to multiple formats.
§Example
use egui_charts::ui::export::{Exportable, ExportConfig, ExportFormat};
struct MyChart {
// chart data
}
impl Exportable for MyChart {
fn export(&self, config: &ExportConfig) -> Result<Vec<u8>, String> {
match config.format {
ExportFormat::Png => {
// Render chart to PNG bytes
Ok(vec![]) // Replace with actual PNG bytes
}
ExportFormat::Svg => {
// Render chart to SVG text bytes
Ok(b"<svg/>".to_vec())
}
ExportFormat::Clipboard => {
// Same as PNG
self.export_png()
}
ExportFormat::Csv => {
// Export bar data as CSV bytes
Ok(b"time,open,high,low,close,volume\n".to_vec())
}
}
}
}Required Methods§
Sourcefn export(&self, config: &ExportConfig) -> Result<Vec<u8>, String>
fn export(&self, config: &ExportConfig) -> Result<Vec<u8>, String>
Exports the chart with the given configuration
§Arguments
config- Export configuration specifying the format
§Returns
Ok(Vec<u8>)- The exported chart as raw bytesErr(String)- An error message if export fails
§Errors
Returns an error if:
- The format is not supported
- Rendering fails
- Memory allocation fails
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".