mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-26 19:41:09 +00:00
Rename TagList::iter_tag_list() to TagList::iter_generic() and ::iter_tag_list_simple() to ::iter()
It's the generic iterator for going over values, and the simple one is the one you usually want. Also rename iterator types, but those are internal anyway.
This commit is contained in:
parent
8a6bcbcedb
commit
9f8ec3b35b
2 changed files with 43 additions and 43 deletions
|
@ -464,20 +464,20 @@ impl TagListRef {
|
||||||
unsafe { ffi::gst_tag_list_get_tag_size(self.as_ptr(), tag_name.to_glib_none().0) }
|
unsafe { ffi::gst_tag_list_get_tag_size(self.as_ptr(), tag_name.to_glib_none().0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter_tag<'a, T: Tag<'a>>(&'a self) -> TagIterator<'a, T> {
|
pub fn iter_tag<'a, T: Tag<'a>>(&'a self) -> TagIter<'a, T> {
|
||||||
TagIterator::new(self)
|
TagIter::new(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter_tag_generic<'a>(&'a self, tag_name: &'a str) -> GenericTagIterator<'a> {
|
pub fn iter_tag_generic<'a>(&'a self, tag_name: &'a str) -> GenericTagIter<'a> {
|
||||||
GenericTagIterator::new(self, tag_name)
|
GenericTagIter::new(self, tag_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter_tag_list(&self) -> TagListIterator {
|
pub fn iter_generic(&self) -> GenericIter {
|
||||||
TagListIterator::new(self)
|
GenericIter::new(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter_tag_list_simple(&self) -> TagListSimpleIterator {
|
pub fn iter(&self) -> Iter {
|
||||||
TagListSimpleIterator::new(self)
|
Iter::new(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_string(&self) -> String {
|
pub fn to_string(&self) -> String {
|
||||||
|
@ -519,17 +519,17 @@ impl PartialEq for TagListRef {
|
||||||
|
|
||||||
impl Eq for TagListRef {}
|
impl Eq for TagListRef {}
|
||||||
|
|
||||||
pub struct TagIterator<'a, T: Tag<'a>> {
|
pub struct TagIter<'a, T: Tag<'a>> {
|
||||||
taglist: &'a TagListRef,
|
taglist: &'a TagListRef,
|
||||||
idx: u32,
|
idx: u32,
|
||||||
size: u32,
|
size: u32,
|
||||||
phantom: PhantomData<T>,
|
phantom: PhantomData<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: Tag<'a>> TagIterator<'a, T> {
|
impl<'a, T: Tag<'a>> TagIter<'a, T> {
|
||||||
fn new(taglist: &'a TagListRef) -> TagIterator<'a, T> {
|
fn new(taglist: &'a TagListRef) -> TagIter<'a, T> {
|
||||||
skip_assert_initialized!();
|
skip_assert_initialized!();
|
||||||
TagIterator {
|
TagIter {
|
||||||
taglist,
|
taglist,
|
||||||
idx: 0,
|
idx: 0,
|
||||||
size: taglist.get_size::<T>(),
|
size: taglist.get_size::<T>(),
|
||||||
|
@ -538,7 +538,7 @@ impl<'a, T: Tag<'a>> TagIterator<'a, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: Tag<'a>> Iterator for TagIterator<'a, T>
|
impl<'a, T: Tag<'a>> Iterator for TagIter<'a, T>
|
||||||
where
|
where
|
||||||
<T as Tag<'a>>::TagType: 'a,
|
<T as Tag<'a>>::TagType: 'a,
|
||||||
T: 'a,
|
T: 'a,
|
||||||
|
@ -567,7 +567,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: Tag<'a>> DoubleEndedIterator for TagIterator<'a, T>
|
impl<'a, T: Tag<'a>> DoubleEndedIterator for TagIter<'a, T>
|
||||||
where
|
where
|
||||||
<T as Tag<'a>>::TagType: 'a,
|
<T as Tag<'a>>::TagType: 'a,
|
||||||
T: 'a,
|
T: 'a,
|
||||||
|
@ -582,24 +582,24 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: Tag<'a>> ExactSizeIterator for TagIterator<'a, T>
|
impl<'a, T: Tag<'a>> ExactSizeIterator for TagIter<'a, T>
|
||||||
where
|
where
|
||||||
<T as Tag<'a>>::TagType: 'a,
|
<T as Tag<'a>>::TagType: 'a,
|
||||||
T: 'a,
|
T: 'a,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GenericTagIterator<'a> {
|
pub struct GenericTagIter<'a> {
|
||||||
taglist: &'a TagListRef,
|
taglist: &'a TagListRef,
|
||||||
name: &'a str,
|
name: &'a str,
|
||||||
idx: u32,
|
idx: u32,
|
||||||
size: u32,
|
size: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> GenericTagIterator<'a> {
|
impl<'a> GenericTagIter<'a> {
|
||||||
fn new(taglist: &'a TagListRef, name: &'a str) -> GenericTagIterator<'a> {
|
fn new(taglist: &'a TagListRef, name: &'a str) -> GenericTagIter<'a> {
|
||||||
skip_assert_initialized!();
|
skip_assert_initialized!();
|
||||||
GenericTagIterator {
|
GenericTagIter {
|
||||||
taglist,
|
taglist,
|
||||||
name,
|
name,
|
||||||
idx: 0,
|
idx: 0,
|
||||||
|
@ -608,7 +608,7 @@ impl<'a> GenericTagIterator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Iterator for GenericTagIterator<'a> {
|
impl<'a> Iterator for GenericTagIter<'a> {
|
||||||
type Item = &'a SendValue;
|
type Item = &'a SendValue;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
@ -633,7 +633,7 @@ impl<'a> Iterator for GenericTagIterator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DoubleEndedIterator for GenericTagIterator<'a> {
|
impl<'a> DoubleEndedIterator for GenericTagIter<'a> {
|
||||||
fn next_back(&mut self) -> Option<Self::Item> {
|
fn next_back(&mut self) -> Option<Self::Item> {
|
||||||
if self.idx == self.size {
|
if self.idx == self.size {
|
||||||
return None;
|
return None;
|
||||||
|
@ -644,19 +644,19 @@ impl<'a> DoubleEndedIterator for GenericTagIterator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ExactSizeIterator for GenericTagIterator<'a> {}
|
impl<'a> ExactSizeIterator for GenericTagIter<'a> {}
|
||||||
|
|
||||||
pub struct TagListIterator<'a> {
|
pub struct GenericIter<'a> {
|
||||||
taglist: &'a TagListRef,
|
taglist: &'a TagListRef,
|
||||||
idx: u32,
|
idx: u32,
|
||||||
size: u32,
|
size: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> TagListIterator<'a> {
|
impl<'a> GenericIter<'a> {
|
||||||
fn new(taglist: &'a TagListRef) -> TagListIterator<'a> {
|
fn new(taglist: &'a TagListRef) -> GenericIter<'a> {
|
||||||
skip_assert_initialized!();
|
skip_assert_initialized!();
|
||||||
let size = taglist.n_tags();
|
let size = taglist.n_tags();
|
||||||
TagListIterator {
|
GenericIter {
|
||||||
taglist,
|
taglist,
|
||||||
idx: 0,
|
idx: 0,
|
||||||
size: if size > 0 { size as u32 } else { 0 },
|
size: if size > 0 { size as u32 } else { 0 },
|
||||||
|
@ -664,8 +664,8 @@ impl<'a> TagListIterator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Iterator for TagListIterator<'a> {
|
impl<'a> Iterator for GenericIter<'a> {
|
||||||
type Item = (&'a str, GenericTagIterator<'a>);
|
type Item = (&'a str, GenericTagIter<'a>);
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
if self.idx >= self.size {
|
if self.idx >= self.size {
|
||||||
|
@ -690,7 +690,7 @@ impl<'a> Iterator for TagListIterator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DoubleEndedIterator for TagListIterator<'a> {
|
impl<'a> DoubleEndedIterator for GenericIter<'a> {
|
||||||
fn next_back(&mut self) -> Option<Self::Item> {
|
fn next_back(&mut self) -> Option<Self::Item> {
|
||||||
if self.idx == self.size {
|
if self.idx == self.size {
|
||||||
return None;
|
return None;
|
||||||
|
@ -702,19 +702,19 @@ impl<'a> DoubleEndedIterator for TagListIterator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ExactSizeIterator for TagListIterator<'a> {}
|
impl<'a> ExactSizeIterator for GenericIter<'a> {}
|
||||||
|
|
||||||
pub struct TagListSimpleIterator<'a> {
|
pub struct Iter<'a> {
|
||||||
taglist: &'a TagListRef,
|
taglist: &'a TagListRef,
|
||||||
idx: u32,
|
idx: u32,
|
||||||
size: u32,
|
size: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> TagListSimpleIterator<'a> {
|
impl<'a> Iter<'a> {
|
||||||
fn new(taglist: &'a TagListRef) -> TagListSimpleIterator<'a> {
|
fn new(taglist: &'a TagListRef) -> Iter<'a> {
|
||||||
skip_assert_initialized!();
|
skip_assert_initialized!();
|
||||||
let size = taglist.n_tags();
|
let size = taglist.n_tags();
|
||||||
TagListSimpleIterator {
|
Iter {
|
||||||
taglist,
|
taglist,
|
||||||
idx: 0,
|
idx: 0,
|
||||||
size: if size > 0 { size as u32 } else { 0 },
|
size: if size > 0 { size as u32 } else { 0 },
|
||||||
|
@ -722,7 +722,7 @@ impl<'a> TagListSimpleIterator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Iterator for TagListSimpleIterator<'a> {
|
impl<'a> Iterator for Iter<'a> {
|
||||||
type Item = (&'a str, glib::SendValue);
|
type Item = (&'a str, glib::SendValue);
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
@ -748,7 +748,7 @@ impl<'a> Iterator for TagListSimpleIterator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DoubleEndedIterator for TagListSimpleIterator<'a> {
|
impl<'a> DoubleEndedIterator for Iter<'a> {
|
||||||
fn next_back(&mut self) -> Option<Self::Item> {
|
fn next_back(&mut self) -> Option<Self::Item> {
|
||||||
if self.idx == self.size {
|
if self.idx == self.size {
|
||||||
return None;
|
return None;
|
||||||
|
@ -760,7 +760,7 @@ impl<'a> DoubleEndedIterator for TagListSimpleIterator<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ExactSizeIterator for TagListSimpleIterator<'a> {}
|
impl<'a> ExactSizeIterator for Iter<'a> {}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
@ -865,7 +865,7 @@ mod tests {
|
||||||
assert_eq!(tags.nth_tag_name(1), *TAG_DURATION);
|
assert_eq!(tags.nth_tag_name(1), *TAG_DURATION);
|
||||||
assert_eq!(tags.get_size_by_name(&TAG_DURATION), 1);
|
assert_eq!(tags.get_size_by_name(&TAG_DURATION), 1);
|
||||||
|
|
||||||
// GenericTagIterator
|
// GenericTagIter
|
||||||
let mut title_iter = tags.iter_tag_generic(&TAG_TITLE);
|
let mut title_iter = tags.iter_tag_generic(&TAG_TITLE);
|
||||||
assert_eq!(title_iter.size_hint(), (3, Some(3)));
|
assert_eq!(title_iter.size_hint(), (3, Some(3)));
|
||||||
let first_title = title_iter.next().unwrap();
|
let first_title = title_iter.next().unwrap();
|
||||||
|
@ -876,8 +876,8 @@ mod tests {
|
||||||
assert_eq!(third_title.get(), Some("third title"));
|
assert_eq!(third_title.get(), Some("third title"));
|
||||||
assert!(title_iter.next().is_none());
|
assert!(title_iter.next().is_none());
|
||||||
|
|
||||||
// TagListIterator
|
// GenericIter
|
||||||
let mut tag_list_iter = tags.iter_tag_list();
|
let mut tag_list_iter = tags.iter_generic();
|
||||||
assert_eq!(tag_list_iter.size_hint(), (2, Some(2)));
|
assert_eq!(tag_list_iter.size_hint(), (2, Some(2)));
|
||||||
|
|
||||||
let (tag_name, mut tag_iter) = tag_list_iter.next().unwrap();
|
let (tag_name, mut tag_iter) = tag_list_iter.next().unwrap();
|
||||||
|
@ -896,8 +896,8 @@ mod tests {
|
||||||
assert_eq!(first_duration.get(), Some(::SECOND * 120));
|
assert_eq!(first_duration.get(), Some(::SECOND * 120));
|
||||||
assert!(tag_iter.next().is_none());
|
assert!(tag_iter.next().is_none());
|
||||||
|
|
||||||
// TagListSimpleIterator
|
// Iter
|
||||||
let mut tag_list_iter = tags.iter_tag_list_simple();
|
let mut tag_list_iter = tags.iter();
|
||||||
assert_eq!(tag_list_iter.size_hint(), (2, Some(2)));
|
assert_eq!(tag_list_iter.size_hint(), (2, Some(2)));
|
||||||
|
|
||||||
let (tag_name, tag_value) = tag_list_iter.next().unwrap();
|
let (tag_name, tag_value) = tag_list_iter.next().unwrap();
|
||||||
|
|
|
@ -97,7 +97,7 @@ impl Serialize for TagListRef {
|
||||||
let tag_count = self.n_tags();
|
let tag_count = self.n_tags();
|
||||||
if tag_count > 0 {
|
if tag_count > 0 {
|
||||||
let mut seq = serializer.serialize_seq(Some(tag_count as usize))?;
|
let mut seq = serializer.serialize_seq(Some(tag_count as usize))?;
|
||||||
let tag_list_iter = self.iter_tag_list();
|
let tag_list_iter = self.iter_generic();
|
||||||
for (tag_name, tag_iter) in tag_list_iter {
|
for (tag_name, tag_iter) in tag_list_iter {
|
||||||
seq.serialize_element(&TagsSer::new(tag_name, tag_iter))?;
|
seq.serialize_element(&TagsSer::new(tag_name, tag_iter))?;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue