mirror of
https://github.com/Dummi26/musicdb.git
synced 2026-05-09 06:08:00 +02:00
small improvements idk i forgot i had a git repo for this project
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
collections::{HashMap, VecDeque},
|
||||
io::{Read, Write},
|
||||
path::PathBuf,
|
||||
};
|
||||
@@ -81,6 +81,32 @@ where
|
||||
Ok(buf)
|
||||
}
|
||||
}
|
||||
impl<C> ToFromBytes for VecDeque<C>
|
||||
where
|
||||
C: ToFromBytes,
|
||||
{
|
||||
fn to_bytes<T>(&self, s: &mut T) -> Result<(), std::io::Error>
|
||||
where
|
||||
T: Write,
|
||||
{
|
||||
self.len().to_bytes(s)?;
|
||||
for elem in self {
|
||||
elem.to_bytes(s)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn from_bytes<T>(s: &mut T) -> Result<Self, std::io::Error>
|
||||
where
|
||||
T: Read,
|
||||
{
|
||||
let len = ToFromBytes::from_bytes(s)?;
|
||||
let mut buf = VecDeque::with_capacity(len);
|
||||
for _ in 0..len {
|
||||
buf.push_back(ToFromBytes::from_bytes(s)?);
|
||||
}
|
||||
Ok(buf)
|
||||
}
|
||||
}
|
||||
impl<A> ToFromBytes for Option<A>
|
||||
where
|
||||
A: ToFromBytes,
|
||||
|
||||
Reference in New Issue
Block a user