@@ -150,11 +150,12 @@ pub struct RepeatTime {
150150
151151impl fmt:: Display for RepeatTime {
152152 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
153- let mut fields = vec ! [ format!( "{}" , self . interval) , format!( "{}" , self . duration) ] ;
153+ write ! ( f, "{} {}" , self . interval, self . duration) ?;
154+
154155 for value in & self . offsets {
155- fields . push ( format ! ( " {value}") ) ;
156+ write ! ( f , " {value}") ? ;
156157 }
157- write ! ( f , "{}" , fields . join ( " " ) )
158+ Ok ( ( ) )
158159 }
159160}
160161
@@ -234,6 +235,59 @@ pub struct SessionDescription {
234235 pub media_descriptions : Vec < MediaDescription > ,
235236}
236237
238+ impl fmt:: Display for SessionDescription {
239+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
240+ write_key_value ( f, "v=" , Some ( & self . version ) ) ?;
241+ write_key_value ( f, "o=" , Some ( & self . origin ) ) ?;
242+ write_key_value ( f, "s=" , Some ( & self . session_name ) ) ?;
243+
244+ write_key_value ( f, "i=" , self . session_information . as_ref ( ) ) ?;
245+
246+ if let Some ( uri) = & self . uri {
247+ write_key_value ( f, "u=" , Some ( uri) ) ?;
248+ }
249+ write_key_value ( f, "e=" , self . email_address . as_ref ( ) ) ?;
250+ write_key_value ( f, "p=" , self . phone_number . as_ref ( ) ) ?;
251+ if let Some ( connection_information) = & self . connection_information {
252+ write_key_value ( f, "c=" , Some ( & connection_information) ) ?;
253+ }
254+
255+ for bandwidth in & self . bandwidth {
256+ write_key_value ( f, "b=" , Some ( & bandwidth) ) ?;
257+ }
258+ for time_description in & self . time_descriptions {
259+ write_key_value ( f, "t=" , Some ( & time_description. timing ) ) ?;
260+ for repeat_time in & time_description. repeat_times {
261+ write_key_value ( f, "r=" , Some ( & repeat_time) ) ?;
262+ }
263+ }
264+
265+ write_key_slice_of_values ( f, "z=" , & self . time_zones ) ?;
266+
267+ write_key_value ( f, "k=" , self . encryption_key . as_ref ( ) ) ?;
268+ for attribute in & self . attributes {
269+ write_key_value ( f, "a=" , Some ( & attribute) ) ?;
270+ }
271+
272+ for media_description in & self . media_descriptions {
273+ write_key_value ( f, "m=" , Some ( & media_description. media_name ) ) ?;
274+ write_key_value ( f, "i=" , media_description. media_title . as_ref ( ) ) ?;
275+ if let Some ( connection_information) = & media_description. connection_information {
276+ write_key_value ( f, "c=" , Some ( & connection_information) ) ?;
277+ }
278+ for bandwidth in & media_description. bandwidth {
279+ write_key_value ( f, "b=" , Some ( & bandwidth) ) ?;
280+ }
281+ write_key_value ( f, "k=" , media_description. encryption_key . as_ref ( ) ) ?;
282+ for attribute in & media_description. attributes {
283+ write_key_value ( f, "a=" , Some ( & attribute) ) ?;
284+ }
285+ }
286+
287+ Ok ( ( ) )
288+ }
289+ }
290+
237291/// Reset cleans the SessionDescription, and sets all fields back to their default values
238292impl SessionDescription {
239293 /// API to match draft-ietf-rtcweb-jsep
@@ -399,61 +453,7 @@ impl SessionDescription {
399453 /// k=* (encryption key)
400454 /// a=* (zero or more media attribute lines)
401455 pub fn marshal ( & self ) -> String {
402- let mut result = String :: new ( ) ;
403-
404- result += key_value_build ( "v=" , Some ( & self . version . to_string ( ) ) ) . as_str ( ) ;
405- result += key_value_build ( "o=" , Some ( & self . origin . to_string ( ) ) ) . as_str ( ) ;
406- result += key_value_build ( "s=" , Some ( & self . session_name ) ) . as_str ( ) ;
407-
408- result += key_value_build ( "i=" , self . session_information . as_ref ( ) ) . as_str ( ) ;
409-
410- if let Some ( uri) = & self . uri {
411- result += key_value_build ( "u=" , Some ( & format ! ( "{uri}" ) ) ) . as_str ( ) ;
412- }
413- result += key_value_build ( "e=" , self . email_address . as_ref ( ) ) . as_str ( ) ;
414- result += key_value_build ( "p=" , self . phone_number . as_ref ( ) ) . as_str ( ) ;
415- if let Some ( connection_information) = & self . connection_information {
416- result += key_value_build ( "c=" , Some ( & connection_information. to_string ( ) ) ) . as_str ( ) ;
417- }
418-
419- for bandwidth in & self . bandwidth {
420- result += key_value_build ( "b=" , Some ( & bandwidth. to_string ( ) ) ) . as_str ( ) ;
421- }
422- for time_description in & self . time_descriptions {
423- result += key_value_build ( "t=" , Some ( & time_description. timing . to_string ( ) ) ) . as_str ( ) ;
424- for repeat_time in & time_description. repeat_times {
425- result += key_value_build ( "r=" , Some ( & repeat_time. to_string ( ) ) ) . as_str ( ) ;
426- }
427- }
428- if !self . time_zones . is_empty ( ) {
429- let mut time_zones = vec ! [ ] ;
430- for time_zone in & self . time_zones {
431- time_zones. push ( time_zone. to_string ( ) ) ;
432- }
433- result += key_value_build ( "z=" , Some ( & time_zones. join ( " " ) ) ) . as_str ( ) ;
434- }
435- result += key_value_build ( "k=" , self . encryption_key . as_ref ( ) ) . as_str ( ) ;
436- for attribute in & self . attributes {
437- result += key_value_build ( "a=" , Some ( & attribute. to_string ( ) ) ) . as_str ( ) ;
438- }
439-
440- for media_description in & self . media_descriptions {
441- result +=
442- key_value_build ( "m=" , Some ( & media_description. media_name . to_string ( ) ) ) . as_str ( ) ;
443- result += key_value_build ( "i=" , media_description. media_title . as_ref ( ) ) . as_str ( ) ;
444- if let Some ( connection_information) = & media_description. connection_information {
445- result += key_value_build ( "c=" , Some ( & connection_information. to_string ( ) ) ) . as_str ( ) ;
446- }
447- for bandwidth in & media_description. bandwidth {
448- result += key_value_build ( "b=" , Some ( & bandwidth. to_string ( ) ) ) . as_str ( ) ;
449- }
450- result += key_value_build ( "k=" , media_description. encryption_key . as_ref ( ) ) . as_str ( ) ;
451- for attribute in & media_description. attributes {
452- result += key_value_build ( "a=" , Some ( & attribute. to_string ( ) ) ) . as_str ( ) ;
453- }
454- }
455-
456- result
456+ self . to_string ( )
457457 }
458458
459459 /// Unmarshal is the primary function that deserializes the session description
0 commit comments