[librsvg: 8/23] AcceptLanguage - add an iter() method
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 8/23] AcceptLanguage - add an iter() method
- Date: Mon, 24 May 2021 17:47:31 +0000 (UTC)
commit b9158d5107111e26ecb2f0f61d8e14636cb8fb8a
Author: Federico Mena Quintero <federico gnome org>
Date: Wed May 19 13:51:12 2021 -0500
AcceptLanguage - add an iter() method
src/accept_language.rs | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
---
diff --git a/src/accept_language.rs b/src/accept_language.rs
index 7e80b892..1cc58835 100644
--- a/src/accept_language.rs
+++ b/src/accept_language.rs
@@ -60,6 +60,10 @@ impl AcceptLanguage {
Ok(AcceptLanguage(items.into_boxed_slice()))
}
}
+
+ pub fn iter(&self) -> impl Iterator<Item = (&LanguageTag, f32)> {
+ self.0.iter().map(|item| (&item.tag, item.weight.numeric()))
+ }
}
impl Item {
@@ -322,4 +326,20 @@ mod tests {
Err(Error::InvalidWeight)
));
}
+
+ #[test]
+ fn iter() {
+ let accept_language = AcceptLanguage::parse("es-MX, en; q=0.5").unwrap();
+ let mut iter = accept_language.iter();
+
+ let (tag, weight) = iter.next().unwrap();
+ assert_eq!(*tag, LanguageTag::parse("es-MX").unwrap());
+ assert_eq!(weight, 1.0);
+
+ let (tag, weight) = iter.next().unwrap();
+ assert_eq!(*tag, LanguageTag::parse("en").unwrap());
+ assert_eq!(weight, 0.5);
+
+ assert!(iter.next().is_none());
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]