Let Sample::new(), TagList::add(), Structure::set() and others take more values by reference instead of by value

This commit is contained in:
Sebastian Dröge 2017-11-26 23:58:02 +02:00
parent b6d13272df
commit b198ee21da
6 changed files with 24 additions and 24 deletions

View file

@ -133,7 +133,7 @@ fn example_main() -> Result<(), Error> {
("Failed to insert sink"), ("Failed to insert sink"),
details: gst::Structure::builder("error-details") details: gst::Structure::builder("error-details")
.field("error", .field("error",
glib::AnySendValue::new(Arc::new(Mutex::new(Some(err))))) &glib::AnySendValue::new(Arc::new(Mutex::new(Some(err)))))
.build() .build()
); );

View file

@ -382,7 +382,7 @@ impl Builder {
} }
} }
pub fn field<V: ToSendValue>(mut self, name: &str, value: V) -> Self { pub fn field<V: ToSendValue>(mut self, name: &str, value: &V) -> Self {
self.s.set(name, value); self.s.set(name, value);
self self
} }
@ -440,11 +440,11 @@ mod tests {
::init().unwrap(); ::init().unwrap();
let caps = Caps::builder("foo/bar") let caps = Caps::builder("foo/bar")
.field("int", 12) .field("int", &12)
.field("bool", true) .field("bool", &true)
.field("string", "bla") .field("string", &"bla")
.field("fraction", Fraction::new(1, 2)) .field("fraction", &Fraction::new(1, 2))
.field("array", Array::new(&[&1, &2])) .field("array", &Array::new(&[&1, &2]))
.build(); .build();
assert_eq!( assert_eq!(
caps.to_string(), caps.to_string(),

View file

@ -30,8 +30,8 @@ unsafe impl MiniObject for SampleRef {
impl GstRc<SampleRef> { impl GstRc<SampleRef> {
pub fn new( pub fn new(
buffer: Option<Buffer>, buffer: Option<&Buffer>,
caps: Option<Caps>, caps: Option<&Caps>,
segment: Option<&Segment>, segment: Option<&Segment>,
info: Option<&StructureRef>, info: Option<&StructureRef>,
) -> Self { ) -> Self {

View file

@ -305,7 +305,7 @@ impl StructureRef {
} }
} }
pub fn set<T: ToSendValue>(&mut self, name: &str, value: T) { pub fn set<T: ToSendValue>(&mut self, name: &str, value: &T) {
let value = value.to_send_value(); let value = value.to_send_value();
self.set_value(name, value); self.set_value(name, value);
} }
@ -608,7 +608,7 @@ impl Builder {
} }
} }
pub fn field<V: ToSendValue>(mut self, name: &str, value: V) -> Self { pub fn field<V: ToSendValue>(mut self, name: &str, value: &V) -> Self {
self.s.set(name, value); self.s.set(name, value);
self self
} }
@ -629,9 +629,9 @@ mod tests {
let mut s = Structure::new_empty("test"); let mut s = Structure::new_empty("test");
assert_eq!(s.get_name(), "test"); assert_eq!(s.get_name(), "test");
s.set("f1", "abc"); s.set("f1", &"abc");
s.set("f2", String::from("bcd")); s.set("f2", &String::from("bcd"));
s.set("f3", 123i32); s.set("f3", &123i32);
assert_eq!(s.get::<&str>("f1").unwrap(), "abc"); assert_eq!(s.get::<&str>("f1").unwrap(), "abc");
assert_eq!(s.get::<&str>("f2").unwrap(), "bcd"); assert_eq!(s.get::<&str>("f2").unwrap(), "bcd");
@ -657,9 +657,9 @@ mod tests {
::init().unwrap(); ::init().unwrap();
let s = Structure::builder("test") let s = Structure::builder("test")
.field("f1", "abc") .field("f1", &"abc")
.field("f2", String::from("bcd")) .field("f2", &String::from("bcd"))
.field("f3", 123i32) .field("f3", &123i32)
.build(); .build();
assert_eq!(s.get_name(), "test"); assert_eq!(s.get_name(), "test");

View file

@ -255,7 +255,7 @@ impl Default for GstRc<TagListRef> {
} }
impl TagListRef { impl TagListRef {
pub fn add<'a, T: Tag<'a>>(&mut self, value: T::TagType, mode: TagMergeMode) pub fn add<'a, T: Tag<'a>>(&mut self, value: &T::TagType, mode: TagMergeMode)
where where
T::TagType: ToSendValue, T::TagType: ToSendValue,
{ {
@ -442,8 +442,8 @@ mod tests {
assert_eq!(tags.to_string(), "taglist;"); assert_eq!(tags.to_string(), "taglist;");
{ {
let tags = tags.get_mut().unwrap(); let tags = tags.get_mut().unwrap();
tags.add::<Title>("some title".into(), TagMergeMode::Append); tags.add::<Title>(&"some title", TagMergeMode::Append);
tags.add::<Duration>((1000u64 * 1000 * 1000 * 120).into(), TagMergeMode::Append); tags.add::<Duration>(&(1000u64 * 1000 * 1000 * 120).into(), TagMergeMode::Append);
} }
assert_eq!( assert_eq!(
tags.to_string(), tags.to_string(),
@ -459,8 +459,8 @@ mod tests {
assert_eq!(tags.to_string(), "taglist;"); assert_eq!(tags.to_string(), "taglist;");
{ {
let tags = tags.get_mut().unwrap(); let tags = tags.get_mut().unwrap();
tags.add::<Title>("some title".into(), TagMergeMode::Append); tags.add::<Title>(&"some title", TagMergeMode::Append);
tags.add::<Duration>((1000u64 * 1000 * 1000 * 120).into(), TagMergeMode::Append); tags.add::<Duration>(&(1000u64 * 1000 * 1000 * 120).into(), TagMergeMode::Append);
} }
assert_eq!(tags.get::<Title>().unwrap().get(), Some("some title")); assert_eq!(tags.get::<Title>().unwrap().get(), Some("some title"));

View file

@ -80,7 +80,7 @@ impl TocRef {
} }
} }
pub fn merge_tags(&mut self, tag_list: TagList, mode: TagMergeMode) { pub fn merge_tags(&mut self, tag_list: &TagList, mode: TagMergeMode) {
unsafe { unsafe {
ffi::gst_toc_merge_tags(self.as_mut_ptr(), tag_list.as_mut_ptr(), mode.to_glib()); ffi::gst_toc_merge_tags(self.as_mut_ptr(), tag_list.as_mut_ptr(), mode.to_glib());
} }
@ -208,7 +208,7 @@ impl TocEntryRef {
} }
} }
pub fn merge_tags(&mut self, tag_list: TagList, mode: TagMergeMode) { pub fn merge_tags(&mut self, tag_list: &TagList, mode: TagMergeMode) {
unsafe { unsafe {
ffi::gst_toc_entry_merge_tags(self.as_mut_ptr(), tag_list.as_mut_ptr(), mode.to_glib()); ffi::gst_toc_entry_merge_tags(self.as_mut_ptr(), tag_list.as_mut_ptr(), mode.to_glib());
} }