Skip to content

Commit acef878

Browse files
authored
implement from and tryfrom string traits for SessionDescription (webrtc-rs#348)
1 parent 3e47da6 commit acef878

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

sdp/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
* Implement from and tryfrom string traits for SessionDescription.
6+
57
## v0.5.3
68

79
* Increased minimum support rust version to `1.60.0`.

sdp/src/description/session.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::collections::HashMap;
2+
use std::convert::TryFrom;
23
use std::time::{Duration, SystemTime, UNIX_EPOCH};
34
use std::{fmt, io};
45
use url::Url;
@@ -563,6 +564,21 @@ impl SessionDescription {
563564
}
564565
}
565566

567+
impl From<SessionDescription> for String {
568+
fn from(sdp: SessionDescription) -> String {
569+
sdp.marshal()
570+
}
571+
}
572+
573+
impl TryFrom<String> for SessionDescription {
574+
type Error = Error;
575+
fn try_from(sdp_string: String) -> Result<Self> {
576+
let mut reader = io::Cursor::new(sdp_string.as_bytes());
577+
let session_description = SessionDescription::unmarshal(&mut reader)?;
578+
Ok(session_description)
579+
}
580+
}
581+
566582
fn s1<'a, R: io::BufRead + io::Seek>(lexer: &mut Lexer<'a, R>) -> Result<Option<StateFn<'a, R>>> {
567583
let (key, _) = read_type(lexer.reader)?;
568584
if &key == b"v=" {

0 commit comments

Comments
 (0)