tglman / persy

@@ -11,11 +11,8 @@
Loading
11 11
    persy::PersyImpl,
12 12
    snapshots::SnapshotId,
13 13
    transaction_impl::TransactionImpl,
14 -
    GenericError,
15 14
};
16 -
use std::{fmt::Display, io::Cursor, str, sync::Arc};
17 -
18 -
use data_encoding::BASE64URL_NOPAD;
15 +
use std::{fmt::Display, io::Cursor, ops::Deref, str, sync::Arc};
19 16
20 17
/// Enum of all the possible Key or Value types for indexes
21 18
#[derive(Clone)]
@@ -122,7 +119,19 @@
Loading
122 119
123 120
/// Wrapper for `Vec<u8>` for use it in index keys or values
124 121
#[derive(Debug, PartialOrd, PartialEq, Clone, Ord, Eq)]
125 -
pub struct ByteVec(pub Vec<u8>);
122 +
pub struct ByteVec(Vec<u8>);
123 +
124 +
impl ByteVec {
125 +
    pub fn new(value: Vec<u8>) -> Self {
126 +
        ByteVec(value)
127 +
    }
128 +
}
129 +
impl Deref for ByteVec {
130 +
    type Target = [u8];
131 +
    fn deref(&self) -> &Self::Target {
132 +
        &self.0
133 +
    }
134 +
}
126 135
127 136
impl From<&[u8]> for ByteVec {
128 137
    fn from(f: &[u8]) -> ByteVec {
@@ -144,15 +153,7 @@
Loading
144 153
145 154
impl Display for ByteVec {
146 155
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
147 -
        write!(f, "{}", BASE64URL_NOPAD.encode(&self.0))
148 -
    }
149 -
}
150 -
151 -
impl std::str::FromStr for ByteVec {
152 -
    type Err = GenericError;
153 -
154 -
    fn from_str(s: &str) -> Result<Self, Self::Err> {
155 -
        Ok(ByteVec(BASE64URL_NOPAD.decode(s.as_bytes())?))
156 +
        write!(f, "{:?}", &self.0)
156 157
    }
157 158
}
158 159
@@ -477,7 +478,7 @@
Loading
477 478
478 479
#[cfg(test)]
479 480
mod tests {
480 -
    use super::{ByteVec, IndexConfig, ValueMode};
481 +
    use super::{IndexConfig, ValueMode};
481 482
    use std::io::Cursor;
482 483
483 484
    #[test]
@@ -497,11 +498,4 @@
Loading
497 498
        let read = IndexConfig::deserialize(&mut Cursor::new(&mut buff)).expect("deserialization works");
498 499
        assert_eq!(cfg, read);
499 500
    }
500 -
501 -
    #[test]
502 -
    fn test_bytevec_to_from_string() {
503 -
        let bv = ByteVec(vec![10, 20]);
504 -
        let nbv = bv.to_string().parse().unwrap();
505 -
        assert_eq!(bv, nbv);
506 -
    }
507 501
}

@@ -363,15 +363,15 @@
Loading
363 363
364 364
impl IndexSerialization for ByteVec {
365 365
    fn serialize(&self, buffer: &mut dyn InfallibleWrite) -> PERes<()> {
366 -
        buffer.write_varint_u32(self.0.len() as u32);
367 -
        buffer.write_all(self.0.as_slice());
366 +
        buffer.write_varint_u32(self.len() as u32);
367 +
        buffer.write_all(self);
368 368
        Ok(())
369 369
    }
370 370
    fn deserialize(value: &mut dyn InfallibleRead) -> PERes<Self> {
371 371
        let vec_size = value.read_varint_u32();
372 372
        let mut slice: Vec<u8> = vec![0; vec_size as usize];
373 373
        value.read_exact(&mut slice);
374 -
        Ok(ByteVec(slice))
374 +
        Ok(ByteVec::new(slice))
375 375
    }
376 376
}
377 377
Files Coverage
src 91.26%
tests 98.59%
Project Totals (37 files) 92.60%
Notifications are pending CI completion. Waiting for GitLab's status webhook to queue notifications. Push notifications now.
1
coverage:
2
  status:
3
    project:
4
      default:
5
        target: 80%
6
        threshold: 1.0%
7
    patch: off
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading