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: EventTypeEvent type (Dialogue, Comment, etc.)
layer: &'a strLayer for drawing order (higher layers drawn on top)
start: &'a strStart time in ASS time format (H:MM:SS.CS)
end: &'a strEnd time in ASS time format (H:MM:SS.CS)
style: &'a strStyle name reference
name: &'a strCharacter name or speaker
margin_l: &'a strLeft margin override (pixels)
margin_r: &'a strRight margin override (pixels)
margin_v: &'a strVertical 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 strEffect specification for special rendering
text: &'a strText content with possible style overrides
span: SpanSpan in source text where this event is defined
Implementations§
Source§impl Event<'_>
impl Event<'_>
Sourcepub const fn is_dialogue(&self) -> bool
pub const fn is_dialogue(&self) -> bool
Check if this is a dialogue event
Returns true for events that should be displayed during playback.
Sourcepub const fn is_comment(&self) -> bool
pub const fn is_comment(&self) -> bool
Check if this is a comment event
Returns true for events that are comments and not displayed.
Sourcepub fn start_time_cs(&self) -> Result<u32, CoreError>
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.
Sourcepub fn end_time_cs(&self) -> Result<u32, CoreError>
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.
Sourcepub fn duration_cs(&self) -> Result<u32, CoreError>
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.
Sourcepub fn to_ass_string(&self) -> String
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"
);Sourcepub fn to_ass_string_with_format(&self, format: &[&str]) -> String
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"
);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 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.