pub enum Section<'a> {
ScriptInfo(ScriptInfo<'a>),
Styles(Vec<Style<'a>>),
Events(Vec<Event<'a>>),
Fonts(Vec<Font<'a>>),
Graphics(Vec<Graphic<'a>>),
}Expand description
Top-level section in an ASS script
Represents the main sections that can appear in an ASS subtitle file. Each variant contains the parsed content of that section with zero-copy string references to the original source text.
§Examples
use ass_core::parser::ast::{Section, ScriptInfo, SectionType, Span};
let info = ScriptInfo { fields: vec![("Title", "Test")], span: Span::new(0, 10, 1, 1) };
let section = Section::ScriptInfo(info);
assert_eq!(section.section_type(), SectionType::ScriptInfo);Variants§
ScriptInfo(ScriptInfo<'a>)
[Script Info] section with metadata
Contains key-value pairs defining script metadata like title, script type, resolution, and other configuration values.
Styles(Vec<Style<'a>>)
[V4+ Styles] section with style definitions
Contains style definitions that can be referenced by events. Each style defines font, colors, positioning, and other visual properties for subtitle rendering.
Events(Vec<Event<'a>>)
[Events\] section with dialogue and commands
Contains dialogue lines, comments, and other timed events that make up the actual subtitle content.
Fonts(Vec<Font<'a>>)
[Fonts\] section with embedded font data
Contains UU-encoded font files embedded in the script. Allows scripts to include custom fonts for portable rendering.
Graphics(Vec<Graphic<'a>>)
[Graphics\] section with embedded images
Contains UU-encoded image files embedded in the script. Used for logos, textures, and other graphical elements.
Implementations§
Source§impl Section<'_>
impl Section<'_>
Sourcepub fn span(&self) -> Option<Span>
pub fn span(&self) -> Option<Span>
Get the span covering this entire section
Computes the span by looking at the content’s spans. Returns None if the section is empty.
Sourcepub const fn section_type(&self) -> SectionType
pub const fn section_type(&self) -> SectionType
Get section type discriminant for efficient matching
Returns the section type without borrowing the section content, allowing for efficient type-based filtering and routing.
§Examples
let info = Section::ScriptInfo(ScriptInfo { fields: Vec::new(), span: Span::new(0, 0, 0, 0) });
assert_eq!(info.section_type(), SectionType::ScriptInfo);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 section reference valid source
Debug helper to ensure zero-copy invariants are maintained. Validates that all string references in the section point to memory within the specified source range.
Only available in debug builds to avoid performance overhead in release builds.
§Arguments
source_range- Valid memory range for source text
§Returns
true if all spans are valid, false otherwise