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