Event

Struct Event 

Source
pub struct Event<'a> {
Show 14 fields pub event_type: EventType, pub layer: &'a str, pub start: &'a str, pub end: &'a str, pub style: &'a str, pub name: &'a str, pub margin_l: &'a str, pub margin_r: &'a str, pub margin_v: &'a str, pub margin_t: Option<&'a str>, pub margin_b: Option<&'a str>, pub effect: &'a str, pub text: &'a str, pub span: Span,
}
Expand description

Event from [Events\] section (dialogue, comments, etc.)

Represents a single event in the subtitle timeline. Events can be dialogue lines, comments, or other commands with associated timing and styling. All fields use zero-copy string references for maximum efficiency.

§Examples

use ass_core::parser::ast::{Event, EventType};

let event = Event {
    event_type: EventType::Dialogue,
    start: "0:00:05.00",
    end: "0:00:10.00",
    text: "Hello, world!",
    ..Event::default()
};

assert!(event.is_dialogue());

Fields§

§event_type: EventType

Event type (Dialogue, Comment, etc.)

§layer: &'a str

Layer for drawing order (higher layers drawn on top)

§start: &'a str

Start time in ASS time format (H:MM:SS.CS)

§end: &'a str

End time in ASS time format (H:MM:SS.CS)

§style: &'a str

Style name reference

§name: &'a str

Character name or speaker

§margin_l: &'a str

Left margin override (pixels)

§margin_r: &'a str

Right margin override (pixels)

§margin_v: &'a str

Vertical margin override (pixels) (V4+)

§margin_t: Option<&'a str>

Top margin override (pixels) (V4++)

§margin_b: Option<&'a str>

Bottom margin override (pixels) (V4++)

§effect: &'a str

Effect specification for special rendering

§text: &'a str

Text content with possible style overrides

§span: Span

Span in source text where this event is defined

Implementations§

Source§

impl Event<'_>

Source

pub const fn is_dialogue(&self) -> bool

Check if this is a dialogue event

Returns true for events that should be displayed during playback.

Source

pub const fn is_comment(&self) -> bool

Check if this is a comment event

Returns true for events that are comments and not displayed.

Source

pub fn start_time_cs(&self) -> Result<u32, CoreError>

Parse start time to centiseconds

Converts the start time string to centiseconds for timing calculations. Uses the standard ASS time format parser.

§Errors

Returns an error if the time format is invalid or cannot be parsed.

Source

pub fn end_time_cs(&self) -> Result<u32, CoreError>

Parse end time to centiseconds

Converts the end time string to centiseconds for timing calculations. Uses the standard ASS time format parser.

§Errors

Returns an error if the time format is invalid or cannot be parsed.

Source

pub fn duration_cs(&self) -> Result<u32, CoreError>

Get duration in centiseconds

Calculates the event duration by subtracting start time from end time. Returns 0 if start time is greater than end time.

§Errors

Returns an error if either start or end time format is invalid.

Source

pub fn to_ass_string(&self) -> String

Convert event to ASS string representation

Generates the standard ASS event line format. Uses margin_v by default, but will use margin_t/margin_b if provided (V4++ format).

§Examples
let event = Event {
    event_type: EventType::Dialogue,
    layer: "0",
    start: "0:00:05.00",
    end: "0:00:10.00",
    style: "Default",
    text: "Hello",
    ..Event::default()
};
assert_eq!(
    event.to_ass_string(),
    "Dialogue: 0,0:00:05.00,0:00:10.00,Default,,0,0,0,,Hello"
);
Source

pub fn to_ass_string_with_format(&self, format: &[&str]) -> String

Convert event to ASS string with specific format

Generates an ASS event line according to the provided format specification. This allows handling both V4+ and V4++ formats, as well as custom formats.

§Arguments
  • format - Field names in order (e.g., ["Layer", "Start", "End", "Style", "Text"])
§Examples
let event = Event {
    event_type: EventType::Comment,
    start: "0:00:00.00",
    end: "0:00:05.00",
    text: "Note",
    ..Event::default()
};
let format = vec!["Start", "End", "Text"];
assert_eq!(
    event.to_ass_string_with_format(&format),
    "Comment: 0:00:00.00,0:00:05.00,Note"
);
Source

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

Available on debug-assertions enabled only.

Validate all spans in this Event reference valid source

Debug helper to ensure zero-copy invariants are maintained. Validates that all string references point to memory within the specified source range.

Only available in debug builds to avoid performance overhead.

Trait Implementations§

Source§

impl<'a> Clone for Event<'a>

Source§

fn clone(&self) -> Event<'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 Event<'a>

Source§

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

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

impl Default for Event<'_>

Source§

fn default() -> Event<'_>

Create default event with safe initial values

Provides a valid default event that can be used as a template or for testing purposes.

Source§

impl<'a> From<&Event<'a>> for OwnedEvent

Source§

fn from(event: &Event<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> PartialEq for Event<'a>

Source§

fn eq(&self, other: &Event<'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 Event<'a>

Source§

impl<'a> StructuralPartialEq for Event<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Event<'a>

§

impl<'a> RefUnwindSafe for Event<'a>

§

impl<'a> Send for Event<'a>

§

impl<'a> Sync for Event<'a>

§

impl<'a> Unpin for Event<'a>

§

impl<'a> UnwindSafe for Event<'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.