|
|
@@ -163,6 +163,7 @@ impl LenIo for String {
|
|
|
|
|
|
fn write<L: Len>(&self, w: &mut Writer) -> Result<()> {
|
|
|
let len = L::try_from(self.len() as u64)
|
|
|
+ .map_err(|_| "conversion to u64 failed")
|
|
|
.map_err(other)?;
|
|
|
len.write(w)?;
|
|
|
w.write_all(self.as_bytes())
|
|
|
@@ -184,7 +185,7 @@ impl<T: Io> LenIo for Vec<T> {
|
|
|
|
|
|
fn write<L: Len>(&self, w: &mut Writer) -> Result<()> {
|
|
|
let len = L::try_from(self.len() as u64)
|
|
|
- .map_err(other)?;
|
|
|
+ .map_err(conversion)?;
|
|
|
len.write(w)?;
|
|
|
for item in self {
|
|
|
item.write(w)?;
|
|
|
@@ -210,7 +211,7 @@ impl<K: Hash + Io + Ord, V: Io> LenIo for HashMap<K, V> {
|
|
|
|
|
|
fn write<L: Len>(&self, w: &mut Writer) -> Result<()> {
|
|
|
let len = L::try_from(self.len() as u64)
|
|
|
- .map_err(other)?;
|
|
|
+ .map_err(conversion)?;
|
|
|
len.write(w)?;
|
|
|
// sorting has some overhead though probably not much overall
|
|
|
let mut keys = self.keys().collect::<Vec<_>>();
|
|
|
@@ -252,9 +253,10 @@ impl LenIo for Duration {
|
|
|
}
|
|
|
|
|
|
fn write<L: Len>(&self, w: &mut Writer) -> Result<()> {
|
|
|
- u64::try_from(self.as_millis())
|
|
|
- .and_then(L::try_from)
|
|
|
- .map_err(other)?
|
|
|
+ let ms = u64::try_from(self.as_millis())
|
|
|
+ .map_err(other)?;
|
|
|
+ L::try_from(ms)
|
|
|
+ .map_err(conversion)?
|
|
|
.write(w)
|
|
|
}
|
|
|
|
|
|
@@ -312,3 +314,8 @@ impl<T: Io, const N: usize> Io for [T; N] {
|
|
|
fn other(error: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Error {
|
|
|
Error::new(ErrorKind::Other, error)
|
|
|
}
|
|
|
+
|
|
|
+// discard error and use a string
|
|
|
+fn conversion<T>(_: T) -> Error {
|
|
|
+ other("failed to convert length to u64")
|
|
|
+}
|