-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
195713f
commit 363882a
Showing
19 changed files
with
257 additions
and
228 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,73 @@ | ||
use std::fmt::{Debug, Formatter}; | ||
use crate::{Doc, Function, Ident, Visibility}; | ||
|
||
pub struct Class<T> { | ||
pub name: Ident, | ||
pub doc: Option<Doc>, | ||
/// `code` is for Python, where we need code like this: | ||
/// class Account(BaseModel): | ||
/// class Config: | ||
/// this_is_a_config_for_pydantic = True | ||
pub code: Option<String>, | ||
pub instance_fields: Vec<Field<T>>, | ||
pub static_fields: Vec<Field<T>>, | ||
pub constructors: Vec<Function<T>>, | ||
/// Use `class_methods` in Rust. | ||
pub class_methods: Vec<Function<T>>, | ||
pub static_methods: Vec<Function<T>>, | ||
pub public: bool, | ||
|
||
pub lifetimes: Vec<String>, | ||
pub decorators: Vec<T>, | ||
pub superclasses: Vec<T>, | ||
} | ||
|
||
#[derive(Debug, Default)] | ||
pub struct Field<T> { | ||
pub name: Ident, | ||
pub ty: T, | ||
pub default: Option<T>, | ||
pub vis: Visibility, | ||
pub doc: Option<Doc>, | ||
pub optional: bool, | ||
pub decorators: Vec<T>, | ||
} | ||
|
||
|
||
impl Debug for Class<String> { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
let public = self.public; | ||
write!(f, "Class {{ name: {name:?}, \ | ||
doc: {doc:?}, \ | ||
instance_fields: todo!, \ | ||
static_fields: todo!, \ | ||
constructors: todo!, \ | ||
class_methods: todo!, \ | ||
static_methods: todo!, \ | ||
public: {public}, \ | ||
lifetimes: todo!, \ | ||
superclasses: todo! }}", | ||
name = self.name, | ||
doc = self.doc, | ||
) | ||
} | ||
} | ||
|
||
impl<T> Default for Class<T> { | ||
fn default() -> Self { | ||
Self { | ||
name: Ident("".to_string()), | ||
code: None, | ||
doc: None, | ||
instance_fields: vec![], | ||
static_fields: vec![], | ||
constructors: vec![], | ||
class_methods: vec![], | ||
static_methods: vec![], | ||
public: false, | ||
lifetimes: vec![], | ||
decorators: vec![], | ||
superclasses: vec![], | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use std::fmt::Formatter; | ||
|
||
/// Localized string | ||
#[derive(Debug, Clone, Eq, PartialEq, Hash, Default)] | ||
pub struct Ident(pub String); | ||
|
||
impl Ident { | ||
pub fn new(s: &'static str) -> Self { | ||
Ident(s.into()) | ||
} | ||
} | ||
|
||
impl std::fmt::Display for Ident { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{}", self.0) | ||
} | ||
} | ||
|
||
impl PartialEq<str> for Ident { | ||
fn eq(&self, other: &str) -> bool { | ||
self.0 == *other | ||
} | ||
} |
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,51 @@ | ||
use crate::{Ident, Visibility}; | ||
|
||
pub struct Import { | ||
/// Path that we're importing from | ||
/// e.g. plaid.model in `from plaid.model import ...` | ||
pub path: String, | ||
/// Specific items that are imported | ||
/// e.g. `Account` in `from plaid.model import Account` | ||
pub imports: Vec<ImportItem>, | ||
/// If a wildcard import and if we want to alias, then alias | ||
pub alias: Option<String>, | ||
pub vis: Visibility, | ||
pub feature: Option<String> | ||
} | ||
|
||
pub struct ImportItem { | ||
/// This might not conform to standard ident rules for the language, so its a string, not an ident. | ||
pub name: String, | ||
pub alias: Option<String>, | ||
} | ||
|
||
impl ImportItem { | ||
pub fn alias(name: &str, alias: &str) -> Self { | ||
Self { name: name.to_string(), alias: Some(alias.to_string()) } | ||
} | ||
} | ||
|
||
impl From<&String> for ImportItem { | ||
fn from(s: &String) -> Self { | ||
Self { name: s.clone(), alias: None } | ||
} | ||
} | ||
|
||
impl From<String> for ImportItem { | ||
fn from(s: String) -> Self { | ||
Self { name: s, alias: None } | ||
} | ||
} | ||
|
||
impl From<&str> for ImportItem { | ||
fn from(s: &str) -> Self { | ||
Self { name: s.to_string(), alias: None } | ||
} | ||
} | ||
|
||
impl From<Ident> for ImportItem { | ||
fn from(s: Ident) -> Self { | ||
Self { name: s.0, alias: None } | ||
} | ||
} | ||
|
Oops, something went wrong.