Enable callers to specify import-style preferences in Importer (#4717)

This commit is contained in:
Charlie Marsh 2023-05-30 12:46:19 -04:00 committed by GitHub
parent ea31229be0
commit f47a517e79
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 116 additions and 34 deletions

View file

@ -31,6 +31,7 @@ pub struct Alias<'a> {
}
impl<'a> Import<'a> {
/// Creates a new `Import` to import the specified module.
pub fn module(name: &'a str) -> Self {
Self {
name: Alias {
@ -41,6 +42,20 @@ impl<'a> Import<'a> {
}
}
impl<'a> ImportFrom<'a> {
/// Creates a new `ImportFrom` to import a member from the specified module.
pub fn member(module: &'a str, name: &'a str) -> Self {
Self {
module: Some(module),
name: Alias {
name,
as_name: None,
},
level: None,
}
}
}
impl std::fmt::Display for AnyImport<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {