mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-22 09:31:06 +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/1520>
This commit is contained in:
parent
500499827d
commit
9a628848cf
1 changed files with 1 additions and 1 deletions
|
@ -483,7 +483,7 @@ impl TagListRef {
|
|||
|
||||
#[doc(alias = "get_index")]
|
||||
#[doc(alias = "gst_tag_list_get_index")]
|
||||
pub fn index<'a, T: Tag<'a>>(&self, idx: usize) -> Option<&'a TagValue<T::TagType>> {
|
||||
pub fn index<'a, T: Tag<'a>>(&'a self, idx: usize) -> 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