Skip to content

Commit

Permalink
feat: add into_owned() to everything
Browse files Browse the repository at this point in the history
by deriving into-owned
  • Loading branch information
hoodie committed Dec 28, 2021
1 parent c0ffeec commit c0ffeec
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 39 deletions.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ edition = "2018"
[dependencies]
nom = "7"
wee_alloc = { version = "0.4", optional = true }

[dependencies.ufmt]
version = "0.1"
features = ["std"]
optional = true

[dependencies.derive-into-owned]
git = "https://github.com/hoodie/derive-into-owned"
branch = "feature/update-syn"

[dev-dependencies]
pretty_assertions = "1"

Expand Down
17 changes: 9 additions & 8 deletions src/attributes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! [6. SDP Attributes](https://tools.ietf.org/html/rfc4566#section-6)
use derive_into_owned::IntoOwned;
use nom::{
branch::alt,
bytes::complete::{is_not, tag},
Expand Down Expand Up @@ -99,7 +100,7 @@ pub mod bundle {
use super::*;

/// `a=group:BUNDLE 0 1`
#[derive(Debug, PartialEq)]
#[derive(Debug, IntoOwned, PartialEq)]
pub struct BundleGroup<'a>(pub Vec<Cow<'a, str>>);

pub fn bundle_group_line(input: &str) -> IResult<&str, BundleGroup> {
Expand Down Expand Up @@ -140,7 +141,7 @@ pub mod rtp {
use super::*;

// a=rtpmap:110 opus/48000/2
#[derive(Debug, PartialEq)]
#[derive(Debug, IntoOwned, PartialEq)]
pub struct Rtp<'a> {
pub payload: u32,
pub codec: Cow<'a, str>,
Expand Down Expand Up @@ -179,7 +180,7 @@ pub mod fmtp {
use super::*;
///<https://tools.ietf.org/html/rfc4588#section-8.1>
/// `a=fmtp:108 profile-level-id=24;object=23;bitrate=64000`
#[derive(Debug, PartialEq)]
#[derive(Debug, IntoOwned, PartialEq)]
pub struct Fmtp<'a> {
pub payload: u32,
pub config: Cow<'a, str>,
Expand Down Expand Up @@ -220,7 +221,7 @@ pub mod control {
use super::*;

/// `a=control:streamid=0`
#[derive(Debug, PartialEq)]
#[derive(Debug, IntoOwned, PartialEq)]
pub struct Control<'a>(pub Cow<'a, str>);

pub fn control_attribute_line(input: &str) -> IResult<&str, Control> {
Expand Down Expand Up @@ -325,7 +326,7 @@ pub mod rtcp_option {
pub mod fingerprint {
use super::*;

#[derive(Debug)]
#[derive(Debug, IntoOwned)]
pub struct Fingerprint<'a> {
pub r#type: Cow<'a, str>,
pub hash: Cow<'a, str>,
Expand Down Expand Up @@ -358,7 +359,7 @@ pub mod fingerprint {
pub mod mid {
use super::*;

#[derive(Debug)]
#[derive(Debug, IntoOwned)]
pub struct Mid<'a>(pub Cow<'a, str>);

pub fn mid_line(input: &str) -> IResult<&str, Mid> {
Expand All @@ -382,7 +383,7 @@ pub mod msid {
use super::*;

/// TODO: type this more strictly, if possible without `Vec`
#[derive(Debug, PartialEq)]
#[derive(Debug, derive_into_owned::IntoOwned, PartialEq)]
pub struct MsidSemantic<'a>(pub Vec<Cow<'a, str>>);

pub fn msid_semantic_line(input: &str) -> IResult<&str, MsidSemantic> {
Expand All @@ -409,7 +410,7 @@ pub mod msid {
);
}

#[derive(Debug, PartialEq)]
#[derive(Debug, IntoOwned, PartialEq)]
pub struct Msid<'a>(pub Vec<Cow<'a, str>>);

pub fn msid_line(input: &str) -> IResult<&str, Msid> {
Expand Down
9 changes: 5 additions & 4 deletions src/attributes/candidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//!
//! read [RFC5245 Section 15.1](https://tools.ietf.org/html/rfc5245#section-15.1)
use derive_into_owned::IntoOwned;
use nom::{
branch::alt,
bytes::complete::tag,
Expand Down Expand Up @@ -46,15 +47,15 @@ pub enum CandidateType {
/// candidate:3348148302 1 udp 2113937151 192.0.2.1 56500 typ host
/// candidate:3348148302 2 udp 2113937151 192.0.2.1 56501 typ host
// "candidate:1853887674 2 udp 1518280447 47.61.61.61 36768 typ srflx raddr 192.168.0.196 rport 36768 generation 0"
#[derive(Debug)]
#[derive(Debug, IntoOwned)]
pub struct Candidate<'a> {
pub foundation: u32,
pub component: CandidateComponent,
pub protocol: CandidateProtocol,
pub priority: u32, // 2043278322
pub addr: IpAddr, // "192.168.0.56"
pub port: u32, // 44323
pub typ: CandidateType, // "host"
pub r#type: CandidateType, // "host"
pub raddr: Option<IpAddr>, // "192.168.0.56"
pub rport: Option<u32>, // 44323
pub tcptype: Option<Cow<'a, str>>,
Expand Down Expand Up @@ -101,7 +102,7 @@ pub fn candidate(input: &str) -> IResult<&str, Candidate> {
priority,
addr,
port,
typ,
r#type,
raddr,
rport,
tcptype,
Expand All @@ -113,7 +114,7 @@ pub fn candidate(input: &str) -> IResult<&str, Candidate> {
priority,
addr,
port,
typ,
r#type,
raddr,
rport,
tcptype,
Expand Down
3 changes: 2 additions & 1 deletion src/attributes/extmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use std::borrow::Cow;

use derive_into_owned::IntoOwned;
use nom::{
bytes::complete::tag,
combinator::{map, opt},
Expand All @@ -16,7 +17,7 @@ use crate::parsers::*;

/// `a=extmap:<value>["/"<direction>] <URI> <extensionattributes>`
///<https://tools.ietf.org/html/rfc8285#section-8>
#[derive(Debug, PartialEq)]
#[derive(Debug, IntoOwned, PartialEq)]
pub struct Extmap<'a> {
pub value: u32,
pub direction: Option<Direction>,
Expand Down
3 changes: 2 additions & 1 deletion src/attributes/ice.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::borrow::Cow;

use derive_into_owned::IntoOwned;
use nom::{branch::alt, bytes::complete::tag, combinator::map, IResult};

#[cfg(test)]
use crate::assert_line;
use crate::parsers::*;

#[derive(Debug, PartialEq)]
#[derive(Debug, IntoOwned, PartialEq)]
#[non_exhaustive]
pub enum IceParameter<'a> {
Ufrag(Cow<'a, str>),
Expand Down
11 changes: 6 additions & 5 deletions src/attributes/rtcp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Rtcp<https://tools.ietf.org/html/rfc3605>
// ///////////////////////
use derive_into_owned::IntoOwned;
use nom::{
branch::alt,
bytes::complete::tag,
Expand Down Expand Up @@ -72,13 +73,13 @@ fn test_rtcp_attribute_line() {
///<https://tools.ietf.org/html/rfc4585#section-4.2>
///<https://datatracker.ietf.org/doc/draft-ietf-mmusic-sdp-mux-attributes/16/?include_text=1>
/// eg `a=rtcp-fb:98 trr-int 100`
#[derive(Debug, PartialEq)]
#[derive(Debug, IntoOwned, PartialEq)]
pub struct Fb<'a> {
pub payload: u32,
pub val: FbVal<'a>,
}

#[derive(Debug, PartialEq)]
#[derive(Debug, IntoOwned, PartialEq)]
#[non_exhaustive]
pub enum FbVal<'a> {
Ack(FbAckParam<'a>),
Expand All @@ -90,7 +91,7 @@ pub enum FbVal<'a> {
},
}

#[derive(Debug, PartialEq)]
#[derive(Debug, IntoOwned, PartialEq)]
#[non_exhaustive]
pub enum FbParam<'a> {
App(Cow<'a, str>),
Expand All @@ -109,7 +110,7 @@ fn read_param(input: &str) -> IResult<&str, FbParam> {
))(input)
}

#[derive(Debug, PartialEq)]
#[derive(Debug, IntoOwned, PartialEq)]
#[non_exhaustive]
pub enum FbAckParam<'a> {
Rpsi,
Expand Down Expand Up @@ -146,7 +147,7 @@ fn test_rtcpfb_ack_param() {
);
}

#[derive(Debug, PartialEq)]
#[derive(Debug, IntoOwned, PartialEq)]
#[non_exhaustive]
pub enum FbNackParam<'a> {
Pli,
Expand Down
3 changes: 2 additions & 1 deletion src/attributes/rtpmap.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::borrow::Cow;

use derive_into_owned::IntoOwned;
use nom::{
branch::alt,
bytes::complete::tag,
Expand Down Expand Up @@ -39,7 +40,7 @@ fn test_read_p_time() {
/// RtpMap
/// `a=rtpmap:<payload type> <encoding name>/<clock rate> [/<encoding` parameters>]
///<https://tools.ietf.org/html/rfc4566#section-6>
#[derive(Debug, PartialEq)]
#[derive(Debug, IntoOwned, PartialEq)]
pub struct RtpMap<'a> {
pub payload_type: u32,
pub encoding_name: Cow<'a, str>,
Expand Down
6 changes: 3 additions & 3 deletions src/attributes/ssrc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::borrow::Cow;

use derive_into_owned::IntoOwned;
use nom::{
branch::alt,
bytes::complete::{is_not, tag},
Expand All @@ -9,12 +10,11 @@ use nom::{
IResult,
};

use crate::parsers::*;
#[cfg(test)]
use crate::{assert_line, assert_line_print};

use crate::parsers::*;

#[derive(Debug, PartialEq)]
#[derive(Debug, IntoOwned, PartialEq)]
pub struct Ssrc<'a> {
pub id: u64,
pub attribute: Cow<'a, str>,
Expand Down
2 changes: 1 addition & 1 deletion src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ impl fmt::Display for Candidate<'_> {
self.priority,
self.addr,
self.port,
self.typ,
self.r#type,
)?;
if let Some(x) = self.raddr {
write!(f, "{}", x)?;
Expand Down
11 changes: 6 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

use std::borrow::Cow;

use derive_into_owned::IntoOwned;
use nom::{branch::alt, bytes::complete::tag, combinator::map, IResult};

#[cfg_attr(feature = "wee_alloc", global_allocator)]
Expand Down Expand Up @@ -57,7 +58,7 @@ use lines::{
use parsers::cowify;

/// Sdp Line
#[derive(Debug)]
#[derive(Debug, IntoOwned)]
#[non_exhaustive]
pub enum SdpLine<'a> {
Session(SessionLine<'a>),
Expand All @@ -66,7 +67,7 @@ pub enum SdpLine<'a> {
}

/// Session Line
#[derive(Debug)]
#[derive(Debug, IntoOwned)]
#[non_exhaustive]
pub enum SessionLine<'a> {
/// `v=0`
Expand Down Expand Up @@ -102,7 +103,7 @@ pub enum SessionLine<'a> {
Media(Media<'a>),
}

#[derive(Debug)]
#[derive(Debug, IntoOwned)]
#[non_exhaustive]
pub enum AttributeLine<'a> {
/// `a=candidate:1853887674 2 udp 1518280447 0.0.0.0 36768 typ srflx raddr 192.168.0.196 rport 36768 generation 0`
Expand Down Expand Up @@ -201,11 +202,11 @@ pub fn attribute_line(input: &str) -> IResult<&str, AttributeLine> {
))(input)
}

#[derive(Debug, Default)]
#[derive(Debug, Default, IntoOwned)]
pub struct MediaSection<'a> {
pub lines: Vec<SdpLine<'a>>,
}
#[derive(Debug, Default)]
#[derive(Debug, Default, IntoOwned)]
pub struct EagerSession<'a> {
pub lines: Vec<SdpLine<'a>>,
pub media: Vec<MediaSection<'a>>,
Expand Down
14 changes: 8 additions & 6 deletions src/lines.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#![allow(dead_code)]

use derive_into_owned::IntoOwned;
use nom::{
branch::alt,
bytes::complete::{tag, take_while},
combinator::map,
sequence::{preceded, separated_pair, tuple},
IResult,
};

use std::borrow::Cow;

pub mod connection;
Expand All @@ -20,7 +22,7 @@ use crate::parsers::*;
pub mod version {
use super::*;

#[derive(Debug, PartialEq)]
#[derive(Debug, IntoOwned, PartialEq)]
pub struct Version(pub u32);

/// "v=0"
Expand All @@ -41,7 +43,7 @@ pub mod session_name {
/// `s=somename`
///
/// <https://tools.ietf.org/html/rfc4566#section-5.3>
#[derive(Debug, PartialEq)]
#[derive(Debug, IntoOwned, PartialEq)]
pub struct SessionName<'a>(pub Cow<'a, str>);

/// "s=somename"
Expand All @@ -67,7 +69,7 @@ pub mod session_information {
use super::*;

/// `i=<session description>`
#[derive(Debug, PartialEq)]
#[derive(Debug, IntoOwned, PartialEq)]
pub struct SessionInformation<'a>(pub Cow<'a, str>);

/// SessionInformation "i=description"
Expand All @@ -89,7 +91,7 @@ pub mod session_information {
pub mod uri {
use super::*;
/// Uri `u=<uri>`
#[derive(Debug, PartialEq)]
#[derive(Debug, IntoOwned, PartialEq)]
pub struct Uri<'a>(pub Cow<'a, str>);

/// "i=description"
Expand All @@ -112,7 +114,7 @@ pub mod email {
use super::*;

/// Email `e=<email-address>`
#[derive(Debug, PartialEq)]
#[derive(Debug, IntoOwned, PartialEq)]
pub struct EmailAddress<'a>(pub Cow<'a, str>);

/// "[email protected]"
Expand All @@ -136,7 +138,7 @@ pub mod email {
pub mod phone_number {
use super::*;
/// Email `p=<phone-number>`
#[derive(Debug, PartialEq)]
#[derive(Debug, IntoOwned, PartialEq)]
pub struct PhoneNumber<'a>(pub Cow<'a, str>);

/// "i=description"
Expand Down
Loading

0 comments on commit c0ffeec

Please sign in to comment.