1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use std::path::PathBuf;

use crate::{TBuffer, TBytes};

impl TBytes for PathBuf {
    fn size(&self) -> usize {
        self.as_os_str().to_os_string().size()
    }

    fn to_bytes(&self) -> Vec<u8> {
        self.as_os_str().to_os_string().to_bytes()
    }

    fn from_bytes(buffer: &mut TBuffer) -> Option<Self>
    where
        Self: Sized,
    {
        let str = std::ffi::OsString::from_bytes(buffer)?;
        Some(PathBuf::from(str))
    }
}