Add test for zero copy
This commit is contained in:
parent
6a67e9444c
commit
99ee250868
|
|
@ -1,7 +1,13 @@
|
|||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
### Custom ###
|
||||
.vscode/
|
||||
|
||||
### Rust ###
|
||||
# Compiled files and executables
|
||||
debug/
|
||||
target/
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
# Backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
### Python ###
|
||||
.mypy_cache/
|
||||
|
|
|
|||
|
|
@ -163,3 +163,26 @@ impl Display for DirDisplayScore<'_> {
|
|||
|
||||
pub type Rank = f64;
|
||||
pub type Epoch = u64;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{Dir, DirList};
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
#[test]
|
||||
fn zero_copy() {
|
||||
let dirs = DirList(vec![Dir {
|
||||
path: "/".into(),
|
||||
rank: 0.0,
|
||||
last_accessed: 0,
|
||||
}]);
|
||||
|
||||
let bytes = dirs.to_bytes().unwrap();
|
||||
let dirs = DirList::from_bytes(&bytes).unwrap();
|
||||
|
||||
for dir in dirs.iter() {
|
||||
assert!(matches!(dir.path, Cow::Borrowed(_)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue