rsvim_core/buf/opt/
file_encoding.rs1use std::fmt::Display;
4use std::string::ToString;
5
6#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
7pub enum FileEncodingOption {
8 Utf8,
9 }
12
13impl Display for FileEncodingOption {
14 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15 match self {
16 FileEncodingOption::Utf8 => write!(f, "utf-8"),
17 }
20 }
21}
22
23impl TryFrom<&str> for FileEncodingOption {
24 type Error = String;
25
26 fn try_from(value: &str) -> Result<Self, Self::Error> {
27 let lower_value = value.to_lowercase();
28 match lower_value.as_str() {
29 "utf-8" | "utf8" => Ok(FileEncodingOption::Utf8),
30 _ => Err("Unknown FileEncoding value".to_string()),
33 }
34 }
35}
36
37#[cfg(test)]
38mod tests {
39 use super::*;
40
41 #[test]
42 fn display1() {
43 let actual1 = format!("{}", FileEncodingOption::Utf8);
44 assert_eq!(actual1, "utf-8");
45 }
46}