Skip to main content

WritableTag

Struct WritableTag 

Source
pub struct WritableTag<'a> {
    pub name: Cow<'a, str>,
    pub value: WritableTagValue<'a>,
}
Expand description

A tag representation that makes writing from custom tags easier.

This is provided so that custom tag implementations may provide an output that does not depend on having parsed data to derive the write output from. This helps with mutability as well as allowing for custom tags to be constructed from scratch (without being parsed from source data).

Fields§

§name: Cow<'a, str>

The name of the tag.

This must include everything after the #EXT prefix and before the : or new line. For example, #EXTM3U has name M3U, #EXT-X-VERSION:3 has name -X-VERSION, etc.

§value: WritableTagValue<'a>

The value of the tag.

The WritableTagValue provides data types that allow for owned data (rather than just borrowed references from parsed input data). See the enum documentation for more information on what values can be defined.

Implementations§

Source§

impl<'a> WritableTag<'a>

Source

pub fn new( name: impl Into<Cow<'a, str>>, value: impl Into<WritableTagValue<'a>>, ) -> Self

Create a new tag.

§Examples
§Empty
WritableTag::new("-X-EXAMPLE", WritableTagValue::Empty);

produces a tag that would write as #EXT-X-EXAMPLE.

§Integer
let explicit = WritableTag::new(
    Cow::Borrowed("-X-EXAMPLE"),
    WritableTagValue::DecimalInteger(42),
);
// Or, with convenience `From<u64>`
let terse = WritableTag::new("-X-EXAMPLE", 42);
assert_eq!(explicit, terse);

produces a tag that would write as #EXT-X-EXAMPLE:42.

§Integer range
let explicit = WritableTag::new(
    Cow::Borrowed("-X-EXAMPLE"),
    WritableTagValue::DecimalIntegerRange(1024, Some(512)),
);
// Or, with convenience `From<(u64, Option<u64>)>`
let terse = WritableTag::new("-X-EXAMPLE", (1024, Some(512)));
assert_eq!(explicit, terse);

produces a tag that would write as #EXT-X-EXAMPLE:1024@512.

§Float with title
let explicit = WritableTag::new(
    Cow::Borrowed("-X-EXAMPLE"),
    WritableTagValue::DecimalFloatingPointWithOptionalTitle(3.14, "pi".into()),
);
// Or, with convenience `From<(f64, impl Into<Cow<str>>)>`
let terse = WritableTag::new("-X-EXAMPLE", (3.14, "pi"));
assert_eq!(explicit, terse);

produces a tag that would write as #EXT-X-EXAMPLE:3.14,pi.

§Date time
let explicit = WritableTag::new(
    Cow::Borrowed("-X-EXAMPLE"),
    WritableTagValue::DateTime(date_time!(2025-08-10 T 21:51:42.123 -05:00)),
);
// Or, with convenience `From<DateTime>`
let terse = WritableTag::new("-X-EXAMPLE", date_time!(2025-08-10 T 21:51:42.123 -05:00));
assert_eq!(explicit, terse);

produces a tag that would write as #EXT-X-EXAMPLE:2025-08-10T21:51:42.123-05:00.

§Attribute list
let explicit = WritableTag::new(
    Cow::Borrowed("-X-EXAMPLE"),
    WritableTagValue::AttributeList(HashMap::from([
        ("VALUE".into(), WritableAttributeValue::DecimalInteger(42)),
    ])),
);
// Or, with convenience `From<[(K, V); N]>`
let terse = WritableTag::new("-X-EXAMPLE", [("VALUE", 42)]);
assert_eq!(explicit, terse);

produces a tag that would write as #EXT-X-EXAMPLE:VALUE=42.

§UTF-8
let explicit = WritableTag::new(
    Cow::Borrowed("-X-EXAMPLE"),
    WritableTagValue::Utf8(Cow::Borrowed("HELLO")),
);
// Or, with convenience `From<&str>`
let terse = WritableTag::new("-X-EXAMPLE", "HELLO");
assert_eq!(explicit, terse);

produces a tag that would write as #EXT-X-EXAMPLE:HELLO.

Trait Implementations§

Source§

impl<'a> Debug for WritableTag<'a>

Source§

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

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

impl<'a> PartialEq for WritableTag<'a>

Source§

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

Auto Trait Implementations§

§

impl<'a> Freeze for WritableTag<'a>

§

impl<'a> RefUnwindSafe for WritableTag<'a>

§

impl<'a> Send for WritableTag<'a>

§

impl<'a> Sync for WritableTag<'a>

§

impl<'a> Unpin for WritableTag<'a>

§

impl<'a> UnsafeUnpin for WritableTag<'a>

§

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