1use std::fmt;
3
4#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
6pub enum Prefix {
7 Cargo,
9
10 Custom(String),
12}
13
14impl Default for Prefix {
15 fn default() -> Self {
17 Self::Cargo
18 }
19}
20
21impl fmt::Display for Prefix {
22 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
23 let prefix = match self {
24 Self::Cargo => "cargo",
25 Self::Custom(prefix) => prefix,
26 };
27
28 prefix.fmt(f)
29 }
30}
31
32#[cfg(test)]
33mod tests {
34 use crate::Prefix;
35
36 #[test]
37 fn test_default() {
38 let prefix = Prefix::default();
39 assert!(matches!(prefix, Prefix::Cargo))
40 }
41
42 #[test]
43 fn test_display_cargo() {
44 let prefix = Prefix::Cargo;
45 let string = format!("{}", prefix);
46 assert_eq!(string, "cargo")
47 }
48
49 #[test]
50 fn test_display_custom() {
51 let prefix = Prefix::Custom("custom".into());
52 let string = format!("{}", prefix);
53 assert_eq!(string, "custom")
54 }
55}