Style

Struct Style 

Source
pub struct Style<'a> {
Show 28 fields pub name: &'a str, pub parent: Option<&'a str>, pub fontname: &'a str, pub fontsize: &'a str, pub primary_colour: &'a str, pub secondary_colour: &'a str, pub outline_colour: &'a str, pub back_colour: &'a str, pub bold: &'a str, pub italic: &'a str, pub underline: &'a str, pub strikeout: &'a str, pub scale_x: &'a str, pub scale_y: &'a str, pub spacing: &'a str, pub angle: &'a str, pub border_style: &'a str, pub outline: &'a str, pub shadow: &'a str, pub alignment: &'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 encoding: &'a str, pub relative_to: Option<&'a str>, pub span: Span,
}
Expand description

Style definition from [V4+ Styles] section

Represents a single style definition that can be referenced by events. All fields are stored as zero-copy string references to the original source text for maximum memory efficiency.

§Examples

use ass_core::parser::ast::Style;

let style = Style {
    name: "Default",
    fontname: "Arial",
    fontsize: "20",
    ..Style::default()
};

assert_eq!(style.name, "Default");
assert_eq!(style.fontname, "Arial");

Fields§

§name: &'a str

Style name (must be unique within script)

§parent: Option<&'a str>

Parent style name for inheritance (None if no inheritance)

§fontname: &'a str

Font name for text rendering

§fontsize: &'a str

Font size in points

§primary_colour: &'a str

Primary color in BGR format (&HBBGGRR)

§secondary_colour: &'a str

Secondary color for collision effects

§outline_colour: &'a str

Outline color

§back_colour: &'a str

Shadow/background color

§bold: &'a str

Bold flag (-1/0 or weight)

§italic: &'a str

Italic flag (0/1)

§underline: &'a str

Underline flag (0/1)

§strikeout: &'a str

Strikeout flag (0/1)

§scale_x: &'a str

Horizontal scale percentage

§scale_y: &'a str

Vertical scale percentage

§spacing: &'a str

Character spacing in pixels

§angle: &'a str

Rotation angle in degrees

§border_style: &'a str

Border style (1=outline+shadow, 3=opaque box)

§outline: &'a str

Outline width in pixels

§shadow: &'a str

Shadow depth in pixels

§alignment: &'a str

Alignment (1-3 + 4/8 for vertical positioning)

§margin_l: &'a str

Left margin in pixels

§margin_r: &'a str

Right margin in pixels

§margin_v: &'a str

Vertical margin in pixels (V4+)

§margin_t: Option<&'a str>

Top margin in pixels (V4++)

§margin_b: Option<&'a str>

Bottom margin in pixels (V4++)

§encoding: &'a str

Font encoding identifier

§relative_to: Option<&'a str>

Positioning context (V4++)

§span: Span

Span in source text where this style is defined

Implementations§

Source§

impl Style<'_>

Source

pub fn to_ass_string(&self) -> String

Convert style to ASS string representation

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

§Examples
let style = Style {
    name: "TestStyle",
    fontname: "Arial",
    fontsize: "20",
    ..Style::default()
};
let ass_string = style.to_ass_string();
assert!(ass_string.starts_with("Style: TestStyle,Arial,20,"));
Source

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

Convert style to ASS string with specific format

Generates an ASS style 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., [“Name”, “Fontname”, “Fontsize”, …])
§Examples
let style = Style {
    name: "Simple",
    fontname: "Arial",
    fontsize: "16",
    ..Style::default()
};
let format = vec!["Name", "Fontname", "Fontsize"];
assert_eq!(
    style.to_ass_string_with_format(&format),
    "Style: Simple,Arial,16"
);
Source

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

Available on debug-assertions enabled only.

Validate all spans in this Style 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 Style<'a>

Source§

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

Source§

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

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

impl Default for Style<'_>

Source§

fn default() -> Style<'_>

Create default ASS style with standard values

Provides the standard ASS default style values as defined in the ASS specification for maximum compatibility.

Source§

impl<'a> PartialEq for Style<'a>

Source§

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

Source§

impl<'a> StructuralPartialEq for Style<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Style<'a>

§

impl<'a> RefUnwindSafe for Style<'a>

§

impl<'a> Send for Style<'a>

§

impl<'a> Sync for Style<'a>

§

impl<'a> Unpin for Style<'a>

§

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