From 7b66325f22b01433b8a04312237c3a8c5e1ce925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 28 Feb 2019 11:26:15 +0200 Subject: [PATCH] sdp: Implement Borrow/BorrowMut/ToOwned for SDPMedia --- gstreamer-sdp/src/sdp_media.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/gstreamer-sdp/src/sdp_media.rs b/gstreamer-sdp/src/sdp_media.rs index c2ceda0b9..2a814c292 100644 --- a/gstreamer-sdp/src/sdp_media.rs +++ b/gstreamer-sdp/src/sdp_media.rs @@ -6,6 +6,7 @@ // // option. This file may not be copied, modified, or distributed // // except according to those terms. +use std::borrow::{Borrow, BorrowMut, ToOwned}; use std::ffi::CStr; use std::fmt; use std::mem; @@ -632,6 +633,30 @@ impl SDPMediaRef { } } +impl Borrow for SDPMedia { + fn borrow(&self) -> &SDPMediaRef { + &*self + } +} + +impl BorrowMut for SDPMedia { + fn borrow_mut(&mut self) -> &mut SDPMediaRef { + &mut *self + } +} + +impl ToOwned for SDPMediaRef { + type Owned = SDPMedia; + + fn to_owned(&self) -> SDPMedia { + unsafe { + let mut ptr = ptr::null_mut(); + ffi::gst_sdp_media_copy(&self.0, &mut ptr); + from_glib_full(ptr) + } + } +} + macro_rules! define_iter( ($name:ident, $typ:ty, $get_item:expr, $get_len:expr) => { #[derive(Debug)]