|
1 | 1 | use crate::error::{Error, Result}; |
2 | | -use std::{fs, io, path::Path, path::PathBuf, str::FromStr}; |
| 2 | +use crate::ostype::OsType; |
| 3 | +use std::{fs, io, path::Path, path::PathBuf}; |
3 | 4 |
|
4 | 5 | #[cfg(test)] |
5 | 6 | mod tests { |
@@ -115,70 +116,6 @@ mod tests { |
115 | 116 | // check that the extracted file contains the same as the initial file |
116 | 117 | assert_eq!(initinal_content, unpacked_content); |
117 | 118 | } |
118 | | - |
119 | | - #[test] |
120 | | - fn test_parse_os_type() { |
121 | | - assert!("HALLO".parse::<OsType>().is_err()); |
122 | | - assert_eq!("Linux".parse::<OsType>().unwrap(), OsType::Linux); |
123 | | - assert_eq!("Darwin".parse::<OsType>().unwrap(), OsType::Darwin); |
124 | | - assert_eq!("WiNdOwS".parse::<OsType>().unwrap(), OsType::Windows); |
125 | | - } |
126 | | -} |
127 | | - |
128 | | -#[derive(Clone, Copy, PartialEq, Eq, Debug)] |
129 | | -pub enum OsType { |
130 | | - Darwin, |
131 | | - Dragonfly, |
132 | | - FreeBSD, |
133 | | - Linux, |
134 | | - NetBSD, |
135 | | - OpenBSD, |
136 | | - // currently there is no Plan9 target for Rust |
137 | | - Plan9, |
138 | | - Solaris, |
139 | | - Windows, |
140 | | -} |
141 | | - |
142 | | -impl OsType { |
143 | | - pub fn stringify(self) -> &'static str { |
144 | | - use OsType::*; |
145 | | - match self { |
146 | | - Darwin => "darwin", |
147 | | - Dragonfly => "dragonfly", |
148 | | - FreeBSD => "freebsd", |
149 | | - Linux => "linux", |
150 | | - NetBSD => "netbsd", |
151 | | - OpenBSD => "openbsd", |
152 | | - Plan9 => "plan9", |
153 | | - Solaris => "solaris", |
154 | | - Windows => "windows", |
155 | | - } |
156 | | - } |
157 | | -} |
158 | | - |
159 | | -impl FromStr for OsType { |
160 | | - type Err = Error; |
161 | | - fn from_str(s: &str) -> Result<Self, Self::Err> { |
162 | | - let lower = s.to_lowercase(); |
163 | | - match lower.as_str() { |
164 | | - // TODO: test if this actually matches |
165 | | - "dragonfly" => Ok(OsType::Dragonfly), |
166 | | - // TODO: test if this actually matches |
167 | | - "freebsd" => Ok(OsType::FreeBSD), |
168 | | - "linux" => Ok(OsType::Linux), |
169 | | - "darwin" => Ok(OsType::Darwin), |
170 | | - // TODO: test if this actually matches |
171 | | - "netbsd" => Ok(OsType::NetBSD), |
172 | | - // TODO: test if this actually matches |
173 | | - "openbsd" => Ok(OsType::OpenBSD), |
174 | | - // TODO: test if this actually matches |
175 | | - "plan9" => Ok(OsType::Plan9), |
176 | | - // TODO: test if this actually matches |
177 | | - "solaris" => Ok(OsType::Solaris), |
178 | | - "windows" => Ok(OsType::Windows), |
179 | | - _ => Err(Error::ParseOS(lower)), |
180 | | - } |
181 | | - } |
182 | 119 | } |
183 | 120 |
|
184 | 121 | // TODO: How to use cfg to pass a value into this function to be able to test it? |
|
0 commit comments