Coverage Report

Created: 2026-07-13 08:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/revision-0.30.0/src/implementations/path.rs
Line
Count
Source
1
use std::path::PathBuf;
2
3
use crate::DeserializeRevisioned;
4
use crate::SerializeRevisioned;
5
6
use super::super::Error;
7
use super::super::Revisioned;
8
use super::vecs::serialize_bytes;
9
10
impl SerializeRevisioned for PathBuf {
11
  #[inline]
12
0
  fn serialize_revisioned<W: std::io::Write>(&self, writer: &mut W) -> Result<(), Error> {
13
0
    match self.to_str() {
14
0
      Some(s) => serialize_bytes(s.as_bytes(), writer),
15
0
      None => Err(Error::InvalidPath),
16
    }
17
0
  }
18
}
19
20
impl DeserializeRevisioned for PathBuf {
21
  #[inline]
22
0
  fn deserialize_revisioned<R: std::io::Read>(reader: &mut R) -> Result<Self, Error> {
23
0
    let s = String::deserialize_revisioned(reader)?;
24
0
    Ok(PathBuf::from(s))
25
0
  }
26
}
27
28
impl Revisioned for PathBuf {
29
  #[inline]
30
0
  fn revision() -> u16 {
31
0
    1
32
0
  }
33
}
34
35
#[cfg(test)]
36
mod tests {
37
38
  use std::path::PathBuf;
39
40
  use crate::implementations::assert_bincode_compat;
41
42
  use super::*;
43
44
  #[test]
45
  fn test_pathbuf() {
46
    let val = PathBuf::from("/test/path/to/file.txt");
47
    assert_bincode_compat(&val);
48
    let mut mem: Vec<u8> = vec![];
49
    val.serialize_revisioned(&mut mem).unwrap();
50
    #[cfg(not(feature = "fixed-width-encoding"))]
51
    assert_eq!(mem.len(), 23);
52
    #[cfg(feature = "fixed-width-encoding")]
53
    assert_eq!(mem.len(), 30);
54
    let out = <PathBuf as DeserializeRevisioned>::deserialize_revisioned(&mut mem.as_slice())
55
      .unwrap();
56
    assert_eq!(val, out);
57
  }
58
}