Enable callers to specify import-style preferences in Importer (#4717)
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user