Skip to content

Commit

Permalink
refactor!: support fieldless enums and data structs
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadow53 authored Jan 24, 2023
2 parents d1dd494 + 7868b01 commit 0e5cf9b
Show file tree
Hide file tree
Showing 8 changed files with 1,127 additions and 359 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ rust-version = "1.62.1"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["complex", "time"]
complex = ["num-complex", "pyo3/num-complex"]
complex = ["num-complex", "num-traits", "pyo3/num-complex"]
extension-module = ["pyo3/extension-module"]

[dependencies]
num-complex = { version = "0.4", optional = true }
num-complex = { version = "0.4.0", optional = true }
num-traits = { version = "0.2.15", optional = true }
paste = "1.0"
pyo3 = { version = "0.17", default-features = false, features = ["macros", "multiple-pymethods"] }
time = { version = "0.3", optional = true }
Expand Down
7 changes: 0 additions & 7 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,43 +85,36 @@
args = ["deadlinks", "--check-http", "--check-intra-doc-links"]

[tasks.deny]
dependencies = ["merge-deny-config"]
install_crate = "cargo-deny"
command = "cargo"
args = ["deny", "check", "-c", "${CARGO_MAKE_WORKING_DIRECTORY}/deny.toml", "all"]

[tasks.deny-advisories]
dependencies = ["merge-deny-config"]
install_crate = "cargo-deny"
command = "cargo"
args = ["deny", "check", "-c", "${CARGO_MAKE_WORKING_DIRECTORY}/deny.toml", "advisories"]

[tasks.deny-ban]
dependencies = ["merge-deny-config"]
install_crate = "cargo-deny"
command = "cargo"
args = ["deny", "check", "-c", "${CARGO_MAKE_WORKING_DIRECTORY}/deny.toml", "ban"]

[tasks.deny-bans]
dependencies = ["merge-deny-config"]
install_crate = "cargo-deny"
command = "cargo"
args = ["deny", "check", "-c", "${CARGO_MAKE_WORKING_DIRECTORY}/deny.toml", "bans"]

[tasks.deny-license]
dependencies = ["merge-deny-config"]
install_crate = "cargo-deny"
command = "cargo"
args = ["deny", "check", "-c", "${CARGO_MAKE_WORKING_DIRECTORY}/deny.toml", "license"]

[tasks.deny-licenses]
dependencies = ["merge-deny-config"]
install_crate = "cargo-deny"
command = "cargo"
args = ["deny", "check", "-c", "${CARGO_MAKE_WORKING_DIRECTORY}/deny.toml", "licenses"]

[tasks.deny-sources]
dependencies = ["merge-deny-config"]
install_crate = "cargo-deny"
command = "cargo"
args = ["deny", "check", "-c", "${CARGO_MAKE_WORKING_DIRECTORY}/deny.toml", "sources"]
Expand Down
10 changes: 5 additions & 5 deletions examples/yak_shaving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,16 @@ pub mod python {
py_wrap_struct! {
PyYak(Yak) as "Yak" {
py -> rs {
py_dict: PyDict => Yak {
let is_shaved: &PyBool = py_dict.as_mapping().get_item("is_shaved")?.downcast()?;
py_dict: Py<PyDict> => Yak {
let is_shaved: &PyBool = py_dict.as_ref(py).as_mapping().get_item("is_shaved")?.downcast()?;
if is_shaved.is_true() {
Ok::<_, PyErr>(Yak::new_shaved())
} else {
Ok(Yak::new())
}
},
py_bool: PyBool => bool {
bool::py_try_from_ref(py, py_bool)
py_bool: Py<PyBool> => bool {
bool::py_try_from(py, &py_bool)
}
},
rs -> py {
Expand Down Expand Up @@ -256,7 +256,7 @@ try:
yak5.shave_with(clippers)
except CloggedClippersError:
pass
clippers.unclog()
yak5.shave_with(clippers)
"#;
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ mod wrappers;

#[cfg(feature = "complex")]
pub use num_complex;
pub use paste;
pub use py_try_from::PyTryFrom;
pub use pyo3;
pub use to_python::ToPython;
Expand Down Expand Up @@ -206,6 +207,7 @@ impl<T> PyWrapperMut for T where T: PyWrapper + AsMut<Self::Inner> {}
macro_rules! create_init_submodule {
(
$(classes: [ $($class: ty),+ ],)?
$(consts: [ $($const: ident),+ ],)?
$(errors: [ $($error: ty),+ ],)?
$(funcs: [ $($func: path),+ ],)?
$(submodules: [ $($mod_name: literal: $init_submod: path),+ ],)?
Expand All @@ -215,6 +217,9 @@ macro_rules! create_init_submodule {
m.add_class::<$class>()?;
)+)?
$($(
m.add(::std::stringify!($const), $crate::ToPython::<$crate::pyo3::Py<$crate::pyo3::PyAny>>::to_python(&$const, _py)?)?;
)+)?
$($(
m.add(std::stringify!($error), _py.get_type::<$error>())?;
)+)?
$($(
Expand Down
Loading

0 comments on commit 0e5cf9b

Please sign in to comment.