pub struct Graphic<'a> {
pub filename: &'a str,
pub data_lines: Vec<&'a str>,
pub span: Span,
}Expand description
Embedded graphic from [Graphics\] section
Represents an image file embedded in the ASS script using UU-encoding. Commonly used for logos, textures, and other graphical elements. Provides lazy decoding for performance.
§Examples
use ass_core::parser::ast::{Graphic, Span};
let graphic = Graphic {
filename: "logo.png",
data_lines: vec!["begin 644 logo.png", "M89PNG..."],
span: Span::new(0, 0, 0, 0),
};
let decoded = graphic.decode_data()?;Fields§
§filename: &'a strGraphic filename as it appears in the [Graphics\] section
data_lines: Vec<&'a str>UU-encoded graphic data lines as zero-copy spans
span: SpanSpan in source text where this graphic is defined
Implementations§
Source§impl Graphic<'_>
impl Graphic<'_>
Sourcepub fn decode_data(&self) -> Result<Vec<u8>, CoreError>
pub fn decode_data(&self) -> Result<Vec<u8>, CoreError>
Decode UU-encoded graphic data with lazy evaluation
Converts the UU-encoded data lines to raw binary image data. This is expensive so it’s only done when explicitly requested.
§Returns
Decoded binary image data on success, error if UU-decoding fails
§Errors
Returns an error if the UU-encoded data is malformed or cannot be decoded.
Sourcepub fn to_ass_string(&self) -> String
pub fn to_ass_string(&self) -> String
Convert graphic to ASS string representation
Generates the graphic entry as it appears in the [Graphics\] section.
§Examples
let graphic = Graphic {
filename: "logo.png",
data_lines: vec!["begin 644 logo.png", "M'XL...", "end"],
span: Span::new(0, 0, 0, 0),
};
let ass_string = graphic.to_ass_string();
assert!(ass_string.starts_with("filename: logo.png\n"));
assert!(ass_string.contains("M'XL..."));Sourcepub fn validate_spans(&self, source_range: &Range<usize>) -> bool
Available on debug-assertions enabled only.
pub fn validate_spans(&self, source_range: &Range<usize>) -> bool
Validate all spans in this Graphic reference valid source
Debug helper to ensure zero-copy invariants are maintained. Validates that filename and all data line references point to memory within the specified source range.
Only available in debug builds to avoid performance overhead.