gstreamer_rtsp_server/
rtsp_token.rs
1use std::fmt;
4
5use crate::ffi;
6use glib::{translate::*, SendValue};
7
8gst::mini_object_wrapper!(RTSPToken, RTSPTokenRef, ffi::GstRTSPToken, || {
9 ffi::gst_rtsp_token_get_type()
10});
11
12impl RTSPToken {
13 #[doc(alias = "gst_rtsp_token_new_empty")]
19 pub fn new_empty() -> Self {
20 assert_initialized_main_thread!();
21 unsafe { from_glib_full(ffi::gst_rtsp_token_new_empty()) }
22 }
23
24 #[doc(alias = "gst_rtsp_token_new")]
25 pub fn builder() -> Builder {
26 skip_assert_initialized!();
27 Builder::new()
28 }
29
30 #[allow(clippy::should_implement_trait)]
31 pub fn from_iter(iter: impl IntoIterator<Item = (impl IntoGStr, SendValue)>) -> RTSPToken {
32 skip_assert_initialized!();
33 let mut token = RTSPToken::new_empty();
34
35 let s = token.get_mut().unwrap().structure_mut();
36 iter.into_iter().for_each(|(f, v)| s.set_value(f, v));
37
38 token
39 }
40}
41
42impl RTSPTokenRef {
43 #[doc(alias = "get_string")]
44 #[doc(alias = "gst_rtsp_token_get_string")]
45 pub fn string(&self, field: &str) -> Option<String> {
46 unsafe {
47 from_glib_none(ffi::gst_rtsp_token_get_string(
48 self.as_mut_ptr(),
49 field.to_glib_none().0,
50 ))
51 }
52 }
53
54 #[doc(alias = "get_structure")]
55 #[doc(alias = "gst_rtsp_token_get_structure")]
56 pub fn structure(&self) -> Option<gst::Structure> {
57 unsafe { from_glib_none(ffi::gst_rtsp_token_get_structure(self.as_mut_ptr())) }
58 }
59
60 #[doc(alias = "gst_rtsp_token_is_allowed")]
61 pub fn is_allowed(&self, field: &str) -> bool {
62 unsafe {
63 from_glib(ffi::gst_rtsp_token_is_allowed(
64 self.as_mut_ptr(),
65 field.to_glib_none().0,
66 ))
67 }
68 }
69
70 #[doc(alias = "get_mut_structure")]
71 pub fn structure_mut(&mut self) -> &mut gst::StructureRef {
72 unsafe {
73 let structure = ffi::gst_rtsp_token_writable_structure(self.as_mut_ptr());
74 gst::StructureRef::from_glib_borrow_mut(structure)
75 }
76 }
77}
78
79impl fmt::Debug for RTSPToken {
80 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
81 RTSPTokenRef::fmt(self, f)
82 }
83}
84
85impl fmt::Debug for RTSPTokenRef {
86 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
87 f.debug_struct("RTSPToken")
88 .field("structure", &self.structure())
89 .finish()
90 }
91}
92
93#[derive(Debug)]
94#[must_use = "The builder must be built to be used"]
95pub struct Builder {
96 token: RTSPToken,
97}
98
99impl Builder {
100 fn new() -> Self {
101 skip_assert_initialized!();
102 Builder {
103 token: RTSPToken::new_empty(),
104 }
105 }
106
107 pub fn field(mut self, name: impl IntoGStr, value: impl Into<glib::Value> + Send) -> Self {
108 self.token
109 .get_mut()
110 .unwrap()
111 .structure_mut()
112 .set(name, value);
113 self
114 }
115
116 gst::impl_builder_gvalue_extra_setters!(field);
117
118 #[must_use = "Building the structure without using it has no effect"]
119 pub fn build(self) -> RTSPToken {
120 self.token
121 }
122}