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
Re-export commonly used types from ass-core 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
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
Trait Implementations§
impl<'a> Eq for Section<'a>
Source§impl<'a> PartialEq for Section<'a>
impl<'a> PartialEq for Section<'a>
Source§impl<'a> Serialize for Section<'a>
impl<'a> Serialize for Section<'a>
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl<'a> StructuralPartialEq for Section<'a>
Auto Trait Implementations§
impl<'a> Freeze for Section<'a>
impl<'a> RefUnwindSafe for Section<'a>
impl<'a> Send for Section<'a>
impl<'a> Sync for Section<'a>
impl<'a> Unpin for Section<'a>
impl<'a> UnsafeUnpin for Section<'a>
impl<'a> UnwindSafe for Section<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more