diff --git a/Cargo.toml b/Cargo.toml index 877e290..1dde61d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "epyxid" edition = "2021" -version = "0.3.0" +version = "0.3.1" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] @@ -9,7 +9,7 @@ name = "epyxid" crate-type = ["cdylib"] [dependencies] -pyo3 = { version = "0.21.2", features = ["extension-module"] } +pyo3 = { version = "0.22.6", features = ["extension-module"] } xid = "1.1.1" [profile.release] diff --git a/pyproject.toml b/pyproject.toml index 24b96d4..d7cb4aa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ requires-python = ">=3.8" authors = [ {name = "Aleksandr Shpak", email = "shpaker@gmail.com"}, ] -version = "0.3.0" +version = "0.3.1" readme = "README.md" license = { file = "LICENSE.txt" } keywords = [ diff --git a/src/lib.rs b/src/lib.rs index 7a31fb3..90cc8be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,8 @@ extern crate core; -use pyo3::prelude::{pymodule, wrap_pyfunction, Bound, PyModule, PyResult, Python}; +use pyo3::prelude::{ + pymodule, wrap_pyfunction, Bound, PyModule, PyModuleMethods, PyResult, Python, +}; use crate::errors::XIDError; use crate::utils::{xid_create, xid_from_bytes, xid_from_str}; diff --git a/src/utils.rs b/src/utils.rs index 0560178..f254c5a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,8 +1,6 @@ use std::str::FromStr; -use pyo3::prelude::PyBytesMethods; -use pyo3::types::PyBytes; -use pyo3::{pyfunction, Bound, PyResult}; +use pyo3::{pyfunction, PyResult}; use xid::{Id, ParseIdError}; use crate::errors::XIDError; @@ -22,8 +20,8 @@ pub fn xid_from_str(s: &str) -> PyResult { } #[pyfunction] -pub fn xid_from_bytes(b: Bound) -> PyResult { - match id_from_bytes(b.as_bytes()) { +pub fn xid_from_bytes(b: Vec) -> PyResult { + match id_from_bytes(&b) { Ok(value) => Ok(XID(value)), Err(error) => Err(XIDError::new_err(error.to_string())), } diff --git a/src/wrapper.rs b/src/wrapper.rs index 6c46867..31b331b 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -1,17 +1,16 @@ -use std::hash::{DefaultHasher, Hash, Hasher}; - use crate::utils::{xid_create, xid_from_bytes, xid_from_str}; +use std::hash::{DefaultHasher, Hash, Hasher}; -use pyo3::types::{PyBytes, PyDateTime, PyString}; +use pyo3::types::{PyBytes, PyDateTime}; use pyo3::{pyclass, pymethods, Bound, FromPyObject, PyResult, Python}; use xid::Id; #[derive(FromPyObject)] -enum XIDReprTypes<'a> { +enum XIDReprTypes { #[pyo3(transparent, annotation = "str")] - String(&'a PyString), + String(String), #[pyo3(transparent, annotation = "bytes")] - Bytes(&'a PyBytes), + Bytes(Vec), } #[pyclass] @@ -20,14 +19,13 @@ pub struct XID(pub Id); #[pymethods] impl XID { #[new] - fn new<'p>(py: Python<'p>, data: Option) -> PyResult { + #[pyo3(signature = (data=None))] + fn py_new(data: Option) -> PyResult { match data { None => xid_create(), Some(repr_value) => match repr_value { - XIDReprTypes::String(value) => xid_from_str(value.to_str().unwrap()), - XIDReprTypes::Bytes(value) => { - xid_from_bytes(PyBytes::new_bound(py, value.as_bytes())) - } + XIDReprTypes::String(value) => xid_from_str(value.as_str()), + XIDReprTypes::Bytes(value) => xid_from_bytes(value), }, } }