| 158 | type Err = PythonVersionDeserializationError; |
| 159 | |
| 160 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 161 | let (major, minor) = s |
| 162 | .split_once('.') |
| 163 | .ok_or_else(|| PythonVersionDeserializationError::WrongPeriodNumber(Box::from(s)))?; |
| 164 | |
| 165 | Self::try_from((major, minor)).map_err(|err| { |
| 166 | // Give a better error message for something like `3.8.5` or `3..8` |
| 167 | if matches!( |
| 168 | err, |
| 169 | PythonVersionDeserializationError::InvalidMinorVersion(_, _) |
| 170 | ) && minor.contains('.') |
| 171 | { |
| 172 | PythonVersionDeserializationError::WrongPeriodNumber(Box::from(s)) |
| 173 | } else { |
| 174 | err |
| 175 | } |
| 176 | }) |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | #[cfg(feature = "serde")] |