Skip to main content

Exportable

Trait Exportable 

Source
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§

Source

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 bytes
  • Err(String) - An error message if export fails
§Errors

Returns an error if:

  • The format is not supported
  • Rendering fails
  • Memory allocation fails

Provided Methods§

Source

fn export_png(&self) -> Result<Vec<u8>, String>

Convenience method to export as PNG

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§