mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-22 01:21:05 +00:00
tags: fix index() lifetime bind
The signature for `TagListRef::index` didn't bind the lifetime of the returned `TagValue` to `&self`. This causes the following code to compile: ```rust 1 let title = { 2 let mut tags = TagList::new(); 3 { 4 let tags = tags.get_mut().unwrap(); 5 tags.add::<Title>(&"some title", TagMergeMode::Append); 6 } 7 8 let title = tags.index::<Title>(0).unwrap(); 9 assert_eq!(title.get(), "some title"); 10 11 title 12 }; 13 14 assert_eq!(title.get(), "some title"); ``` ... but it panics at runtime on the last `title.get()`: ``` Invalid tag type: WrongValueType(ValueTypeMismatchError { actual: <invalid>, requested: gchararray }) ``` Indeed, the `title` `TagValue` is freed with the `tags` on line 12. This commit fixes the function signature so the returned `TagValue` can't outlive its `TagListRef`. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1526>
This commit is contained in:
parent
b9307ca258
commit
8a08557ce4
1 changed files with 1 additions and 1 deletions
|
@ -480,7 +480,7 @@ impl TagListRef {
|
|||
|
||||
#[doc(alias = "get_index")]
|
||||
#[doc(alias = "gst_tag_list_get_index")]
|
||||
pub fn index<'a, T: Tag<'a>>(&self, idx: u32) -> Option<&'a TagValue<T::TagType>> {
|
||||
pub fn index<'a, T: Tag<'a>>(&'a self, idx: u32) -> Option<&'a TagValue<T::TagType>> {
|
||||
self.index_generic(T::tag_name(), idx).map(|value| {
|
||||
if !value.is::<T::TagType>() {
|
||||
panic!(
|
||||
|
|
Loading…
Reference in a new issue