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>
impl<'a> WritableTag<'a>
Sourcepub fn new(
name: impl Into<Cow<'a, str>>,
value: impl Into<WritableTagValue<'a>>,
) -> Self
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.