sdp_nom/
sdp_line.rs

1use derive_into_owned::IntoOwned;
2use enum_as_inner::EnumAsInner;
3use nom::{branch::alt, combinator::map, IResult};
4use std::borrow::Cow;
5
6use crate::{
7    attributes::{attribute_line, AttributeLine},
8    lines::{self, session_line, SessionLine},
9    parsers::cowify,
10};
11
12/// Sdp Line
13#[derive(Clone, IntoOwned, EnumAsInner, PartialEq, Eq)]
14#[cfg_attr(feature = "debug", derive(Debug))]
15#[cfg_attr(
16    feature = "serde",
17    derive(serde::Serialize, serde::Deserialize),
18    serde(rename_all = "camelCase")
19)]
20pub enum SdpLine<'a> {
21    Session(SessionLine<'a>),
22    Attribute(AttributeLine<'a>),
23    Comment(Cow<'a, str>),
24}
25
26pub fn sdp_line(input: &str) -> IResult<&str, SdpLine> {
27    alt((
28        map(session_line, SdpLine::Session),
29        map(attribute_line, SdpLine::Attribute),
30        map(cowify(lines::comment::comment_line), SdpLine::Comment),
31    ))(input)
32}