Section

Enum Section 

Source
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<'_>

Source

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.

Source

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);
Source

pub fn validate_spans(&self, source_range: &Range<usize>) -> bool

Available on debug-assertions enabled only.

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§

Source§

impl<'a> Clone for Section<'a>

Source§

fn clone(&self) -> Section<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Section<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'a> PartialEq for Section<'a>

Source§

fn eq(&self, other: &Section<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Eq for Section<'a>

Source§

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> UnwindSafe for Section<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.