file_operation/file/impl.rs
1use super::*;
2
3/// Provides conversion implementation from byte vector to FileDataString.
4impl From<Vec<u8>> for FileDataString {
5 /// Converts a byte vector to FileDataString.
6 ///
7 /// # Arguments
8 ///
9 /// - `Vec<u8>` - The byte vector to convert.
10 ///
11 /// # Returns
12 ///
13 /// - `FileDataString` - The converted string wrapper.
14 fn from(bytes: Vec<u8>) -> Self {
15 FileDataString(
16 String::from_utf8(bytes).unwrap_or_else(|_: std::string::FromUtf8Error| String::new()),
17 )
18 }
19}
20
21/// Provides Display trait implementation for FileDataString.
22impl fmt::Display for FileDataString {
23 /// Formats the FileDataString for display.
24 ///
25 /// # Arguments
26 ///
27 /// - `&mut fmt::Formatter<'_>` - The formatter to write to.
28 ///
29 /// # Returns
30 ///
31 /// - `fmt::Result` - The result of the formatting operation.
32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33 write!(f, "{}", self.0)
34 }
35}