-
Notifications
You must be signed in to change notification settings - Fork 770
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract from_py_with parsing into its own module
- Loading branch information
1 parent
7d76bc7
commit e2ed1fc
Showing
3 changed files
with
33 additions
and
15 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,27 @@ | ||
use proc_macro2::TokenStream; | ||
use quote::ToTokens; | ||
use syn::spanned::Spanned; | ||
use syn::{Meta, MetaNameValue, Result}; | ||
|
||
#[derive(Clone, Debug, PartialEq)] | ||
pub struct FromPyWithAttribute(syn::ExprPath); | ||
|
||
impl FromPyWithAttribute { | ||
pub fn from_meta(meta: Meta) -> Result<Self> { | ||
if let Meta::NameValue(MetaNameValue { | ||
lit: syn::Lit::Str(string_literal), | ||
.. | ||
}) = meta | ||
{ | ||
let expr_path = string_literal.parse::<syn::ExprPath>()?; | ||
return Ok(FromPyWithAttribute(expr_path)); | ||
} | ||
bail_spanned!(meta.span() => "expected a name-value: `pyo3(from_py_with = \"func\")` ") | ||
} | ||
} | ||
|
||
impl ToTokens for FromPyWithAttribute { | ||
fn to_tokens(&self, tokens: &mut TokenStream) { | ||
self.0.to_tokens(tokens) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
#[macro_use] | ||
mod utils; | ||
|
||
mod attrs; | ||
mod defs; | ||
mod from_pyobject; | ||
mod konst; | ||
|