phink_lib/instrumenter/
path.rs

1use serde::Deserialize;
2use serde_derive::Serialize;
3use std::{
4    fmt::{
5        Display,
6        Formatter,
7    },
8    path::{
9        Path,
10        PathBuf,
11    },
12};
13
14pub const DEFAULT_PATH_PATTERN_INSTRUMENTEDPATH: &str = "ink_fuzzed_";
15
16#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)]
17pub struct InstrumentedPath {
18    pub path: PathBuf,
19}
20impl Display for InstrumentedPath {
21    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
22        write!(f, "{}", self.path.to_str().unwrap())
23    }
24}
25
26impl From<PathBuf> for InstrumentedPath {
27    fn from(path: PathBuf) -> Self {
28        Self { path }
29    }
30}
31impl From<&str> for InstrumentedPath {
32    fn from(path: &str) -> Self {
33        Self {
34            path: PathBuf::from(path),
35        }
36    }
37}
38impl Default for InstrumentedPath {
39    /// By default, we create a random folder in `/tmp/ink_fuzzed_1`
40    fn default() -> Self {
41        Self {
42            path: Path::new("/tmp").join(DEFAULT_PATH_PATTERN_INSTRUMENTEDPATH.to_string() + "1"),
43        }
44    }
45}
46
47#[cfg(test)]
48mod tests {
49    use crate::instrumenter::path::InstrumentedPath;
50
51    #[test]
52    fn test_display_for_default_instrumentedpath() {
53        let inst = InstrumentedPath::default();
54        assert_eq!(inst.to_string(), "/tmp/ink_fuzzed_1");
55    }
56}