-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate interpreter selectors into
implementation
and platform
m…
…odules (#3332) Split out of #3266 The "selector" concept doesn't seem well enough defined as-is. For example, `PythonVersion` belongs there but isn't present. Going for smaller modules instead.
- Loading branch information
Showing
5 changed files
with
69 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::{ | ||
fmt::{self, Display}, | ||
str::FromStr, | ||
}; | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum Error { | ||
#[error("Unknown Python implementation `{0}`")] | ||
UnknownImplementation(String), | ||
} | ||
|
||
#[derive(Debug, Eq, PartialEq, Clone, Copy)] | ||
pub enum ImplementationName { | ||
Cpython, | ||
} | ||
|
||
impl ImplementationName { | ||
#[allow(dead_code)] | ||
pub(crate) fn iter() -> impl Iterator<Item = &'static ImplementationName> { | ||
static NAMES: &[ImplementationName] = &[ImplementationName::Cpython]; | ||
NAMES.iter() | ||
} | ||
|
||
pub fn as_str(&self) -> &str { | ||
match self { | ||
Self::Cpython => "cpython", | ||
} | ||
} | ||
} | ||
|
||
impl FromStr for ImplementationName { | ||
type Err = Error; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
match s.to_ascii_lowercase().as_str() { | ||
"cpython" => Ok(Self::Cpython), | ||
_ => Err(Error::UnknownImplementation(s.to_string())), | ||
} | ||
} | ||
} | ||
|
||
impl Display for ImplementationName { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.write_str(self.as_str()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters