EventBuilder

Struct EventBuilder 

Source
pub struct EventBuilder<'a> { /* private fields */ }
Expand description

Builder for creating ASS events with fluent API

Provides an ergonomic way to construct ASS events with method chaining. Supports all event types and automatically handles format validation.

§Examples

use ass_editor::{EventBuilder, EditorDocument};

let mut doc = EditorDocument::new();

// Create a dialogue event
let event_line = EventBuilder::dialogue()
    .start_time("0:00:00.00")
    .end_time("0:00:05.00")
    .style("Default")
    .speaker("Character")
    .text("Hello, world!")
    .layer(0)
    .build()
    .unwrap();

// Add to document
doc.add_event_line(&event_line).unwrap();

Implementations§

Source§

impl<'a> EventBuilder<'a>

Source

pub fn new() -> Self

Create a new event builder

Source

pub fn dialogue() -> Self

Create a dialogue event builder

Source

pub fn comment() -> Self

Create a comment event builder

Source

pub fn start_time<S: Into<Cow<'a, str>>>(self, time: S) -> Self

Set start time (e.g., “0:00:05.00”)

Source

pub fn end_time<S: Into<Cow<'a, str>>>(self, time: S) -> Self

Set end time (e.g., “0:00:10.00”)

Source

pub fn speaker<S: Into<Cow<'a, str>>>(self, name: S) -> Self

Set speaker/character name

Source

pub fn text<S: Into<Cow<'a, str>>>(self, text: S) -> Self

Set dialogue text

Source

pub fn style<S: Into<Cow<'a, str>>>(self, style: S) -> Self

Set style name

Source

pub fn layer(self, layer: u32) -> Self

Set layer (higher layers render on top)

Source

pub fn margin_left(self, margin: u32) -> Self

Set left margin

Source

pub fn margin_right(self, margin: u32) -> Self

Set right margin

Source

pub fn margin_vertical(self, margin: u32) -> Self

Set vertical margin

Source

pub fn margin_top(self, margin: u32) -> Self

Set top margin (V4++)

Source

pub fn margin_bottom(self, margin: u32) -> Self

Set bottom margin (V4++)

Source

pub fn effect<S: Into<Cow<'a, str>>>(self, effect: S) -> Self

Set effect

Source

pub fn build(self) -> Result<String>

Build the event (validates required fields)

Source

pub fn build_with_version(self, version: ScriptVersion) -> Result<String>

Build the event with a specific format version

Source

pub fn build_with_format(&self, format: &[&str]) -> Result<String>

Build the event with a specific format line The format parameter should contain field names like [“Layer”, “Start”, “End”, “Style”, “Text”]

Trait Implementations§

Source§

impl<'a> Debug for EventBuilder<'a>

Source§

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

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

impl<'a> Default for EventBuilder<'a>

Source§

fn default() -> EventBuilder<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for EventBuilder<'a>

§

impl<'a> RefUnwindSafe for EventBuilder<'a>

§

impl<'a> Send for EventBuilder<'a>

§

impl<'a> Sync for EventBuilder<'a>

§

impl<'a> Unpin for EventBuilder<'a>

§

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