// Common case is there is only 1 value, optimize for that iflet (1, Some(1)) = values.size_hint() { return values
.next()
.expect("size_hint claimed 1 item")
.clone()
.into();
}
// Otherwise, there are multiple, so this should merge them into 1. letmut buf = values
.next()
.cloned()
.map(|val| BytesMut::from(val.as_bytes()))
.unwrap_or_else(|| BytesMut::new());
for val in values {
buf.extend_from_slice(&[Sep::BYTE, b' ']);
buf.extend_from_slice(val.as_bytes());
}
let val = HeaderValue::from_maybe_shared(buf.freeze())
.expect("comma separated HeaderValues are valid");
val.into()
}
}
// TODO: would be great if there was a way to de-dupe these with above impl<Sep: Separator> FromIterator<HeaderValue> for FlatCsv<Sep> { fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = HeaderValue>,
{ letmut values = iter.into_iter();
// Common case is there is only 1 value, optimize for that iflet (1, Some(1)) = values.size_hint() { return values.next().expect("size_hint claimed 1 item").into();
}
// Otherwise, there are multiple, so this should merge them into 1. letmut buf = values
.next()
.map(|val| BytesMut::from(val.as_bytes()))
.unwrap_or_else(|| BytesMut::new());
for val in values {
buf.extend_from_slice(&[Sep::BYTE, b' ']);
buf.extend_from_slice(val.as_bytes());
}
let val = HeaderValue::from_maybe_shared(buf.freeze())
.expect("comma separated HeaderValues are valid");
val.into()
}
}
#[cfg(test)] mod tests { usesuper::*;
#[test] fn comma() { let val = HeaderValue::from_static("aaa, b; bb, ccc"); let csv = FlatCsv::<Comma>::from(val);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.