trying to raise an error

This commit is contained in:
Rob Walker
2018-07-25 03:35:36 -07:00
parent 8b01e6ac0b
commit 9c7913ac9e
3 changed files with 28 additions and 9 deletions

View File

@ -139,6 +139,12 @@ impl Default for Blob {
}
}
//#[derive(Debug)]
//pub enum BlobError {
// /// the Blob's meta and data are not self-consistent
// BadState,
//}
pub struct Recycler<T> {
gc: Arc<Mutex<Vec<Arc<RwLock<T>>>>>,
}
@ -373,18 +379,32 @@ impl Blob {
pub fn data_mut(&mut self) -> &mut [u8] {
&mut self.data[BLOB_HEADER_SIZE..]
}
pub fn get_size(&self) -> Result<usize> {
let size = self.get_data_size()? as usize;
assert_eq!(self.meta.size, size);
// TODO: return an error instead of panicking
Ok(size)
pub fn get_size(&self) -> usize {
let size = self.get_data_size().unwrap() as usize;
if self.meta.size == size {
size - BLOB_HEADER_SIZE
} else {
0
}
// TODO: return a Result<usize> instead of
// returning zero
//
//let size = self.get_data_size()? as usize;
//if self.meta.size == size {
// Ok(size - BLOB_HEADER_SIZE)
//} else {
// // these don't work...
// Err("bad state")
// // Err(BlobError::BadState)
//}
}
pub fn set_size(&mut self, size: usize) {
let new_size = size + BLOB_HEADER_SIZE;
self.meta.size = new_size;
self.set_data_size(new_size as u64).unwrap();
}
pub fn recv_from(re: &BlobRecycler, socket: &UdpSocket) -> Result<SharedBlobs> {
let mut v = VecDeque::new();
//DOCUMENTED SIDE-EFFECT