1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-05-24 19:28:31 +00:00

minor improvements to documentation

This commit is contained in:
Luro02 2020-04-09 10:50:41 +02:00
parent ec0b5cdb21
commit fdc3442bb6
No known key found for this signature in database
GPG key ID: B66FD4F74501A9CF
2 changed files with 35 additions and 80 deletions

View file

@ -10,10 +10,9 @@ use crate::utils::{quote, tag, unquote};
use crate::{Error, RequiredVersion}; use crate::{Error, RequiredVersion};
/// The data of [`ExtXSessionData`]. /// The data of [`ExtXSessionData`].
#[derive(Hash, Eq, Ord, Debug, PartialEq, Clone, PartialOrd)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum SessionData { pub enum SessionData {
/// This variant contains the data identified by the /// Contains the data identified by the [`ExtXSessionData::data_id`].
/// [`ExtXSessionData::data_id`].
/// ///
/// If a [`language`] is specified, this variant should contain a /// If a [`language`] is specified, this variant should contain a
/// human-readable string written in the specified language. /// human-readable string written in the specified language.
@ -31,7 +30,6 @@ pub enum SessionData {
/// Allows arbitrary session data to be carried in a [`MasterPlaylist`]. /// Allows arbitrary session data to be carried in a [`MasterPlaylist`].
/// ///
/// [`MasterPlaylist`]: crate::MasterPlaylist /// [`MasterPlaylist`]: crate::MasterPlaylist
/// [4.3.4.4. EXT-X-SESSION-DATA]: https://tools.ietf.org/html/rfc8216#section-4.3.4.4
#[derive(ShortHand, Builder, Hash, Eq, Ord, Debug, PartialEq, Clone, PartialOrd)] #[derive(ShortHand, Builder, Hash, Eq, Ord, Debug, PartialEq, Clone, PartialOrd)]
#[builder(setter(into))] #[builder(setter(into))]
#[shorthand(enable(must_use, into))] #[shorthand(enable(must_use, into))]
@ -39,25 +37,6 @@ pub struct ExtXSessionData {
/// This should conform to a [reverse DNS] naming convention, such as /// This should conform to a [reverse DNS] naming convention, such as
/// `com.example.movie.title`. /// `com.example.movie.title`.
/// ///
/// # Example
///
/// ```
/// # use hls_m3u8::tags::ExtXSessionData;
/// use hls_m3u8::tags::SessionData;
///
/// let mut session_data = ExtXSessionData::new(
/// "com.example.movie.title",
/// SessionData::Uri("https://www.example.com/".to_string()),
/// );
///
/// session_data.set_data_id("com.ironrust.movie.title");
///
/// assert_eq!(
/// session_data.data_id(),
/// &"com.ironrust.movie.title".to_string()
/// );
/// ```
///
/// # Note /// # Note
/// ///
/// There is no central registration authority, so a value /// There is no central registration authority, so a value
@ -70,50 +49,13 @@ pub struct ExtXSessionData {
/// The [`SessionData`] associated with the /// The [`SessionData`] associated with the
/// [`data_id`](ExtXSessionData::data_id). /// [`data_id`](ExtXSessionData::data_id).
/// ///
/// # Example
///
/// ```
/// # use hls_m3u8::tags::ExtXSessionData;
/// use hls_m3u8::tags::SessionData;
///
/// let mut session_data = ExtXSessionData::new(
/// "com.example.movie.title",
/// SessionData::Uri("https://www.example.com/".to_string()),
/// );
///
/// session_data.set_data(SessionData::Uri(
/// "https://www.example.com/data.json".to_string(),
/// ));
///
/// assert_eq!(
/// session_data.data(),
/// &SessionData::Uri("https://www.example.com/data.json".to_string())
/// );
/// ```
///
/// # Note /// # Note
/// ///
/// This field is required. /// This field is required.
#[shorthand(disable(into))] #[shorthand(enable(skip))]
data: SessionData, pub data: SessionData,
/// The `language` attribute identifies the language of the [`SessionData`]. /// The `language` attribute identifies the language of the [`SessionData`].
/// ///
/// # Example
///
/// ```
/// # use hls_m3u8::tags::ExtXSessionData;
/// use hls_m3u8::tags::SessionData;
///
/// let mut session_data = ExtXSessionData::new(
/// "com.example.movie.title",
/// SessionData::Uri("https://www.example.com/".to_string()),
/// );
///
/// session_data.set_language(Some("en"));
///
/// assert_eq!(session_data.language(), Some(&"en".to_string()));
/// ```
///
/// # Note /// # Note
/// ///
/// This field is optional and the provided value should conform to /// This field is optional and the provided value should conform to
@ -135,9 +77,9 @@ impl ExtXSessionData {
/// # use hls_m3u8::tags::ExtXSessionData; /// # use hls_m3u8::tags::ExtXSessionData;
/// use hls_m3u8::tags::SessionData; /// use hls_m3u8::tags::SessionData;
/// ///
/// ExtXSessionData::new( /// let session_data = ExtXSessionData::new(
/// "com.example.movie.title", /// "com.example.movie.title",
/// SessionData::Uri("https://www.example.com/".to_string()), /// SessionData::Uri("https://www.example.com/".into()),
/// ); /// );
/// ``` /// ```
#[must_use] #[must_use]
@ -159,10 +101,10 @@ impl ExtXSessionData {
/// ///
/// let session_data = ExtXSessionData::builder() /// let session_data = ExtXSessionData::builder()
/// .data_id("com.example.movie.title") /// .data_id("com.example.movie.title")
/// .data(SessionData::Value("some data".to_string())) /// .data(SessionData::Value("some data".into()))
/// .language("en") /// .language("en")
/// .build()?; /// .build()?;
/// # Ok::<(), Box<dyn ::std::error::Error>>(()) /// # Ok::<(), String>(())
/// ``` /// ```
#[must_use] #[must_use]
pub fn builder() -> ExtXSessionDataBuilder { ExtXSessionDataBuilder::default() } pub fn builder() -> ExtXSessionDataBuilder { ExtXSessionDataBuilder::default() }
@ -177,7 +119,7 @@ impl ExtXSessionData {
/// ///
/// let session_data = ExtXSessionData::with_language( /// let session_data = ExtXSessionData::with_language(
/// "com.example.movie.title", /// "com.example.movie.title",
/// SessionData::Value("some data".to_string()), /// SessionData::Value("some data".into()),
/// "en", /// "en",
/// ); /// );
/// ``` /// ```
@ -244,17 +186,20 @@ impl FromStr for ExtXSessionData {
} }
let data_id = data_id.ok_or_else(|| Error::missing_value("EXT-X-DATA-ID"))?; let data_id = data_id.ok_or_else(|| Error::missing_value("EXT-X-DATA-ID"))?;
let data = { let data = {
if let Some(value) = session_value { if let Some(value) = session_value {
if uri.is_some() { if uri.is_some() {
return Err(Error::custom("Unexpected URI")); return Err(Error::custom("unexpected URI"));
} else { } else {
SessionData::Value(value) SessionData::Value(value)
} }
} else if let Some(uri) = uri { } else if let Some(uri) = uri {
SessionData::Uri(uri) SessionData::Uri(uri)
} else { } else {
return Err(Error::invalid_input()); return Err(Error::custom(
"expected either `SessionData::Uri` or `SessionData::Value`",
));
} }
}; };
@ -286,19 +231,27 @@ mod test {
assert_eq!($struct, $str.parse().unwrap()); assert_eq!($struct, $str.parse().unwrap());
)+ )+
assert!("#EXT-X-SESSION-DATA:\ assert!(
DATA-ID=\"foo\",\ concat!(
LANGUAGE=\"baz\"" "#EXT-X-SESSION-DATA:",
"DATA-ID=\"foo\",",
"LANGUAGE=\"baz\""
)
.parse::<ExtXSessionData>() .parse::<ExtXSessionData>()
.is_err()); .is_err()
);
assert!("#EXT-X-SESSION-DATA:\ assert!(
DATA-ID=\"foo\",\ concat!(
LANGUAGE=\"baz\",\ "#EXT-X-SESSION-DATA:",
VALUE=\"VALUE\",\ "DATA-ID=\"foo\",",
URI=\"https://www.example.com/\"" "LANGUAGE=\"baz\",",
"VALUE=\"VALUE\",",
"URI=\"https://www.example.com/\""
)
.parse::<ExtXSessionData>() .parse::<ExtXSessionData>()
.is_err()); .is_err()
);
} }
} }

View file

@ -10,7 +10,9 @@ use crate::utils::{quote, tag, unquote};
use crate::Error; use crate::Error;
/// A server may offer multiple [`MediaPlaylist`] files to provide different /// A server may offer multiple [`MediaPlaylist`] files to provide different
/// encodings of the same presentation. If it does so, it should provide /// encodings of the same presentation.
///
/// If it does so, it should provide
/// a [`MasterPlaylist`] that lists each [`VariantStream`] to allow /// a [`MasterPlaylist`] that lists each [`VariantStream`] to allow
/// clients to switch between encodings dynamically. /// clients to switch between encodings dynamically.
/// ///