Skip to main content

HlsLine

Enum HlsLine 

Source
pub enum HlsLine<'a, Custom = NoCustomTag>
where Custom: CustomTag<'a>,
{ KnownTag(KnownTag<'a, Custom>), UnknownTag(UnknownTag<'a>), Comment(Cow<'a, str>), Uri(Cow<'a, str>), Blank, }
Expand description

A parsed line from a HLS playlist.

The HLS specification, in Section 4.1. Definition of a Playlist, defines lines in a playlist as such:

Each line is a URI, is blank, or starts with the character ‘#’. Lines that start with the character ‘#’ are either comments or tags. Tags begin with #EXT.

This data structure follows that guidance but also adds HlsLine::UnknownTag and KnownTag::Custom. These cases are described in more detail within their own documentation, but in short, the first allows us to capture tags that are not yet known to the library (providing at least a split between name and value), while the second allows a user of the library to define their own custom tag specification that can be then parsed into a strongly typed structure within a HlsLine::KnownTag by the library.

Variants§

§

KnownTag(KnownTag<'a, Custom>)

A tag known to the library, either via the included definitions of HLS tags as specified in the draft-pantos-hls Internet-Draft, or via a custom tag registration provided by the user of the library.

See KnownTag for more information.

§

UnknownTag(UnknownTag<'a>)

A tag, as defined by the #EXT prefix, but not one that is known to the library, or that is deliberately ignored via ParsingOptions.

See UnknownTag for more information.

§

Comment(Cow<'a, str>)

A comment line. These are lines that begin with # and are followed by a string of UTF-8 characters (though not BOM or UTF-8 control characters). The line is terminated by either a line feed (\n) or a carriage return followed by a line feed (\r\n).

The associated value is a std::borrow::Cow to allow for both a user constructed value and also a copy-free reference to the original parsed data. It includes all characters after the # (including any whitespace) and does not include the line break characters. Below demonstrates this:

let original = "# Comment line. Note the leading space.\r\n";
let line = parse(original, &options)?.parsed;
assert_eq!(
    HlsLine::Comment(Cow::Borrowed(" Comment line. Note the leading space.")),
    line,
);
§

Uri(Cow<'a, str>)

A URI line. These are lines that do not begin with # and are not empty. It is important to note that the library does not do any validation on the line being a valid URI. The only validation that happens is that line can be represented as a UTF-8 string (internally we use std::str::from_utf8). This means that the line may contain characters that are invalid in a URI, or may otherwise not make sense in the context of the parsed playlist. It is up to the user of the library to validate the URI, perhaps using a URL parsing library (such as url).

The associated value is a std::borrow::Cow to allow for both a user constructed value and also a copy-free reference to the original parsed data. It includes all characters up until, but not including, the line break characters. The following demonstrates this:

let expected = "hi.m3u8";
// Demonstrating that new line characters are not included:
assert_eq!(
    HlsLine::Uri(Cow::Borrowed(expected)),
    parse("hi.m3u8\n", &options)?.parsed,
);
assert_eq!(
    HlsLine::Uri(Cow::Borrowed(expected)),
    parse("hi.m3u8\r\n", &options)?.parsed,
);
assert_eq!(
    HlsLine::Uri(Cow::Borrowed(expected)),
    parse("hi.m3u8", &options)?.parsed,
);
§

Blank

A blank line. This line contained no characters other than a new line. Note that since the library does not validate characters in a URI line, a line comprised entirely of whitespace will still be parsed as a URI line, rather than a blank line. As mentioned, it is up to the user of the library to properly validate URI lines.

// Demonstrating what is considered a blank line:
assert_eq!(
    HlsLine::Blank,
    parse("", &options)?.parsed,
);
assert_eq!(
    HlsLine::Blank,
    parse("\n", &options)?.parsed,
);
assert_eq!(
    HlsLine::Blank,
    parse("\r\n", &options)?.parsed,
);
// Demonstrating that a whitespace only line is still parsed as a URI:
assert_eq!(
    HlsLine::Uri(Cow::Borrowed("    ")),
    parse("    \n", &options)?.parsed,
);

Implementations§

Source§

impl<'a> HlsLine<'a>

Source

pub fn comment(comment: impl Into<Cow<'a, str>>) -> Self

Convenience constructor for HlsLine::Comment. This will construct the line with the generic Custom in HlsLine::KnownTag being NoCustomTag.

Source

pub fn uri(uri: impl Into<Cow<'a, str>>) -> Self

Convenience constructor for HlsLine::Uri. This will construct the line with the generic Custom in HlsLine::KnownTag being NoCustomTag.

Source

pub fn blank() -> Self

Convenience constructor for HlsLine::Blank. This will construct the line with the generic Custom in HlsLine::KnownTag being NoCustomTag.

Trait Implementations§

Source§

impl<'a, Custom> Clone for HlsLine<'a, Custom>
where Custom: CustomTag<'a> + Clone,

Source§

fn clone(&self) -> HlsLine<'a, Custom>

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, Custom> Debug for HlsLine<'a, Custom>
where Custom: CustomTag<'a> + Debug,

Source§

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

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

impl<'a, Custom> From<Bitrate<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: Bitrate<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<Byterange<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: Byterange<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<ContentSteering<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: ContentSteering<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<CustomTagAccess<'a, Custom>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: CustomTagAccess<'a, Custom>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<Daterange<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: Daterange<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<Define<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: Define<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<Discontinuity> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: Discontinuity) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<DiscontinuitySequence<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: DiscontinuitySequence<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<Endlist> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: Endlist) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<Gap> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: Gap) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<IFrameStreamInf<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: IFrameStreamInf<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<IFramesOnly> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: IFramesOnly) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<IndependentSegments> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: IndependentSegments) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<Inf<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: Inf<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<Key<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: Key<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<M3u> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: M3u) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<Map<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: Map<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<Media<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: Media<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<MediaSequence<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: MediaSequence<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<Part<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: Part<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<PartInf<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: PartInf<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<PlaylistType> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: PlaylistType) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<PreloadHint<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: PreloadHint<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<ProgramDateTime<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: ProgramDateTime<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<RenditionReport<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: RenditionReport<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<ServerControl<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: ServerControl<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<SessionData<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: SessionData<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<SessionKey<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: SessionKey<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<Skip<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: Skip<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<Start<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: Start<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<StreamInf<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: StreamInf<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<Tag<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: Tag<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<Targetduration<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: Targetduration<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<UnknownTag<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: UnknownTag<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> From<Version<'a>> for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Source§

fn from(tag: Version<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Custom> PartialEq for HlsLine<'a, Custom>
where Custom: CustomTag<'a> + PartialEq,

Source§

fn eq(&self, other: &HlsLine<'a, Custom>) -> 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, Custom> StructuralPartialEq for HlsLine<'a, Custom>
where Custom: CustomTag<'a>,

Auto Trait Implementations§

§

impl<'a, Custom> Freeze for HlsLine<'a, Custom>
where Custom: Freeze,

§

impl<'a, Custom> RefUnwindSafe for HlsLine<'a, Custom>
where Custom: RefUnwindSafe,

§

impl<'a, Custom> Send for HlsLine<'a, Custom>
where Custom: Send,

§

impl<'a, Custom> Sync for HlsLine<'a, Custom>
where Custom: Sync,

§

impl<'a, Custom> Unpin for HlsLine<'a, Custom>
where Custom: Unpin,

§

impl<'a, Custom> UnsafeUnpin for HlsLine<'a, Custom>
where Custom: UnsafeUnpin,

§

impl<'a, Custom> UnwindSafe for HlsLine<'a, Custom>
where Custom: UnwindSafe,

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.