vector/sinks/file/
bytes_path.rs1use std::path::Path;
4
5use bytes::Bytes;
6
7#[derive(Debug, Clone)]
8pub struct BytesPath {
9 #[cfg(unix)]
10 path: Bytes,
11 #[cfg(windows)]
12 path: std::path::PathBuf,
13}
14
15impl BytesPath {
16 #[cfg(unix)]
17 pub const fn new(path: Bytes) -> Self {
18 Self { path }
19 }
20 #[cfg(windows)]
21 pub fn new(path: Bytes) -> Self {
22 let utf8_string = String::from_utf8_lossy(&path[..]);
23 let path = std::path::PathBuf::from(utf8_string.as_ref());
24 Self { path }
25 }
26}
27
28impl AsRef<Path> for BytesPath {
29 #[cfg(unix)]
30 fn as_ref(&self) -> &Path {
31 use std::os::unix::ffi::OsStrExt;
32 let os_str = std::ffi::OsStr::from_bytes(&self.path);
33 Path::new(os_str)
34 }
35 #[cfg(windows)]
36 fn as_ref(&self) -> &Path {
37 &self.path.as_ref()
38 }
39}