mirror of https://github.com/fafhrd91/actix-web
make `size_hint` work properly
This commit is contained in:
parent
3fe4e383bd
commit
618ed2d821
|
|
@ -547,20 +547,18 @@ impl<'de> de::VariantAccess<'de> for UnitVariant {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ValueSeq<'de> {
|
struct ValueSeq<'de> {
|
||||||
value: &'de str,
|
|
||||||
elems: std::str::Split<'de, char>,
|
elems: std::str::Split<'de, char>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> ValueSeq<'de> {
|
impl<'de> ValueSeq<'de> {
|
||||||
fn new(value: &'de str) -> Self {
|
fn new(value: &'de str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
value,
|
|
||||||
elems: value.split('/'),
|
elems: value.split('/'),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn len(&self) -> usize {
|
fn len(&self) -> usize {
|
||||||
self.value.split('/').filter(|s| !s.is_empty()).count()
|
self.elems.clone().filter(|s| !s.is_empty()).count()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -757,6 +755,19 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_value_seq_size_hint_counts_remaining_elements() {
|
||||||
|
use serde::de::SeqAccess as _;
|
||||||
|
|
||||||
|
let mut seq = ValueSeq::new("tail/with/slash");
|
||||||
|
|
||||||
|
assert_eq!(seq.size_hint(), Some(3));
|
||||||
|
|
||||||
|
let elem = seq.next_element::<String>().unwrap();
|
||||||
|
assert_eq!(elem.as_deref(), Some("tail"));
|
||||||
|
assert_eq!(seq.size_hint(), Some(2));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_extract_errors() {
|
fn test_extract_errors() {
|
||||||
let mut router = Router::<()>::build();
|
let mut router = Router::<()>::build();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue