-
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.
add #[pyo3(from_py_with="...")] attribute (#1411)
* allow from_py_with inside #[derive(FromPyObject)] * split up FnSpec::parse
- Loading branch information
1 parent
a9f064d
commit 554cffd
Showing
17 changed files
with
485 additions
and
145 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
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,22 @@ | ||
use syn::spanned::Spanned; | ||
use syn::{ExprPath, Lit, Meta, MetaNameValue, Result}; | ||
|
||
#[derive(Clone, Debug, PartialEq)] | ||
pub struct FromPyWithAttribute(pub ExprPath); | ||
|
||
impl FromPyWithAttribute { | ||
pub fn from_meta(meta: Meta) -> Result<Self> { | ||
let string_literal = match meta { | ||
Meta::NameValue(MetaNameValue { | ||
lit: Lit::Str(string_literal), | ||
.. | ||
}) => string_literal, | ||
meta => { | ||
bail_spanned!(meta.span() => "expected a name-value: `pyo3(from_py_with = \"func\")`") | ||
} | ||
}; | ||
|
||
let expr_path = string_literal.parse::<ExprPath>()?; | ||
Ok(FromPyWithAttribute(expr_path)) | ||
} | ||
} |
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; | ||
|
Oops, something went wrong.