Skip to content

Commit

Permalink
bump pyo3 (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
diceroll123 authored Sep 29, 2024
1 parent 2ece8be commit a104145
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name = "neofoodclub"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.20.2", features = ["extension-module", "abi3-py39"] }
pyo3 = { version = "0.21.0", features = ["extension-module", "abi3-py39"] }
neofoodclub = { path = "./neofoodclub_rs" }
chrono = "0.4.38"

Expand Down
14 changes: 7 additions & 7 deletions src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ impl Arena {
}

#[getter]
fn foods<'a>(&self, py: Python<'a>) -> PyResult<Option<&'a PyTuple>> {
fn foods<'a>(&self, py: Python<'a>) -> PyResult<Option<Bound<'a, PyTuple>>> {
let elements = &self.inner.foods;

match elements {
Some(foods) => Ok(Some(PyTuple::new(py, foods))),
Some(foods) => Ok(Some(PyTuple::new_bound(py, foods))),
None => Ok(None),
}
}
Expand All @@ -53,9 +53,9 @@ impl Arena {
}

#[getter]
fn pirate_ids<'a>(&self, py: Python<'a>) -> PyResult<&'a PyTuple> {
fn pirate_ids<'a>(&self, py: Python<'a>) -> PyResult<Bound<'a, PyTuple>> {
let elements = &self.inner.ids();
Ok(PyTuple::new(py, elements))
Ok(PyTuple::new_bound(py, elements))
}

#[getter]
Expand Down Expand Up @@ -174,13 +174,13 @@ impl Arenas {
}

#[getter]
fn pirate_ids<'a>(&self, py: Python<'a>) -> PyResult<&'a PyTuple> {
let elements: Vec<&PyTuple> = self
fn pirate_ids<'a>(&self, py: Python<'a>) -> PyResult<Bound<'a, PyTuple>> {
let elements: Vec<Bound<'a, PyTuple>> = self
.arenas()
.iter()
.map(|a| a.pirate_ids(py).expect("failed to get pirate ids"))
.collect();
Ok(PyTuple::new(py, elements))
Ok(PyTuple::new_bound(py, elements))
}

#[getter]
Expand Down
16 changes: 8 additions & 8 deletions src/bets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ impl Bets {
}

#[getter(bet_amounts)]
fn get_amounts<'a>(&self, py: Python<'a>) -> PyResult<Option<&'a PyTuple>> {
fn get_amounts<'a>(&self, py: Python<'a>) -> PyResult<Option<Bound<'a, PyTuple>>> {
let elements = &self.inner.bet_amounts;

match elements {
Some(amounts) => Ok(Some(PyTuple::new(py, amounts))),
Some(amounts) => Ok(Some(PyTuple::new_bound(py, amounts))),
None => Ok(None),
}
}
Expand Down Expand Up @@ -59,8 +59,8 @@ impl Bets {
}

#[getter]
fn binaries<'a>(&self, py: Python<'a>) -> PyResult<&'a PyTuple> {
Ok(PyTuple::new(py, self.inner.get_binaries()))
fn binaries<'a>(&self, py: Python<'a>) -> PyResult<Bound<'a, PyTuple>> {
Ok(PyTuple::new_bound(py, self.inner.get_binaries()))
}

#[getter]
Expand Down Expand Up @@ -102,14 +102,14 @@ impl Bets {
}

#[getter]
fn indices<'a>(&self, py: Python<'a>) -> PyResult<&'a PyTuple> {
fn indices<'a>(&self, py: Python<'a>) -> PyResult<Bound<'a, PyTuple>> {
let indicies = self.inner.get_indices();
let py_indicies: Vec<&'a PyTuple> = indicies
let py_indicies: Vec<Bound<'a, PyTuple>> = indicies
.iter()
.map(|index| PyTuple::new(py, index))
.map(|index| PyTuple::new_bound(py, index))
.collect();

Ok(PyTuple::new(py, py_indicies))
Ok(PyTuple::new_bound(py, py_indicies))
}

fn net_expected(&self, nfc: &NeoFoodClub) -> f64 {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use pyo3::prelude::*;

#[pymodule]
#[pyo3(name = "neofoodclub")]
fn neofoodclub_rs(_py: Python, m: &PyModule) -> PyResult<()> {
fn neofoodclub_rs(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<math::Math>()?;
m.add_class::<modifier::Modifier>()?;
m.add_class::<nfc::NeoFoodClub>()?;
Expand Down
38 changes: 22 additions & 16 deletions src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@ impl Math {
}

#[staticmethod]
fn binary_to_indices(py: Python, binary: u32) -> PyResult<&PyTuple> {
fn binary_to_indices<'a>(py: Python<'a>, binary: u32) -> PyResult<Bound<'a, PyTuple>> {
let elements = neofoodclub::math::binary_to_indices(binary);
Ok(PyTuple::new(py, elements))
Ok(PyTuple::new_bound(py, elements))
}

#[staticmethod]
fn bets_hash_to_bet_indices<'a>(py: Python<'a>, bets_hash: &'a str) -> PyResult<&'a PyTuple> {
fn bets_hash_to_bet_indices<'a>(
py: Python<'a>,
bets_hash: &'a str,
) -> PyResult<Bound<'a, PyTuple>> {
let elements = neofoodclub::math::bets_hash_to_bet_indices(bets_hash);
Ok(PyTuple::new(py, elements))
Ok(PyTuple::new_bound(py, elements))
}

#[staticmethod]
Expand All @@ -54,15 +57,18 @@ impl Math {
fn amounts_hash_to_bet_amounts<'a>(
py: Python<'a>,
amounts_hash: &'a str,
) -> PyResult<&'a PyTuple> {
) -> PyResult<Bound<'a, PyTuple>> {
let elements = neofoodclub::math::amounts_hash_to_bet_amounts(amounts_hash);
Ok(PyTuple::new(py, elements))
Ok(PyTuple::new_bound(py, elements))
}

#[staticmethod]
fn bets_hash_to_bet_binaries<'a>(py: Python<'a>, bets_hash: &'a str) -> PyResult<&'a PyTuple> {
fn bets_hash_to_bet_binaries<'a>(
py: Python<'a>,
bets_hash: &'a str,
) -> PyResult<Bound<'a, PyTuple>> {
let elements = neofoodclub::math::bets_hash_to_bet_binaries(bets_hash);
Ok(PyTuple::new(py, elements))
Ok(PyTuple::new_bound(py, elements))
}

#[staticmethod]
Expand All @@ -71,28 +77,28 @@ impl Math {
}

#[staticmethod]
fn bets_indices_to_bet_binaries(
py: Python<'_>,
fn bets_indices_to_bet_binaries<'a>(
py: Python<'a>,
bets_indices: Vec<[u8; 5]>,
) -> PyResult<&PyTuple> {
) -> PyResult<Bound<'a, PyTuple>> {
let elements = neofoodclub::math::bets_indices_to_bet_binaries(bets_indices);
Ok(PyTuple::new(py, elements))
Ok(PyTuple::new_bound(py, elements))
}

#[staticmethod]
fn build_chance_objects(
py: Python<'_>,
fn build_chance_objects<'a>(
py: Python<'a>,
bets: Vec<[u8; 5]>,
bet_odds: Vec<u32>,
probabilities: [[f64; 5]; 5],
) -> PyResult<&PyTuple> {
) -> PyResult<Bound<'a, PyTuple>> {
let py_structs: Vec<PyObject> =
neofoodclub::math::build_chance_objects(&bets, &bet_odds, probabilities)
.into_iter()
.map(|chance| Chance::from(chance).into_py(py))
.collect();

Ok(PyTuple::new(py, py_structs))
Ok(PyTuple::new_bound(py, py_structs))
}

#[staticmethod]
Expand Down
28 changes: 14 additions & 14 deletions src/nfc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl NeoFoodClub {
#[classmethod]
#[pyo3(signature = (json, bet_amount=None, probability_model=None, modifier=None))]
fn from_json(
_cls: &PyType,
_cls: &Bound<'_, PyType>,
json: &str,
bet_amount: Option<u32>,
probability_model: Option<u8>,
Expand All @@ -70,7 +70,7 @@ impl NeoFoodClub {
#[classmethod]
#[pyo3(signature = (url, bet_amount=None, probability_model=None, modifier=None))]
fn from_url(
_cls: &PyType,
_cls: &Bound<'_, PyType>,
url: &str,
bet_amount: Option<u32>,
probability_model: Option<u8>,
Expand Down Expand Up @@ -128,9 +128,9 @@ impl NeoFoodClub {
}

#[getter]
fn winners<'a>(&self, py: Python<'a>) -> PyResult<&'a PyTuple> {
fn winners<'a>(&self, py: Python<'a>) -> PyResult<Bound<'a, PyTuple>> {
let elements = self.inner.winners();
Ok(PyTuple::new(py, elements))
Ok(PyTuple::new_bound(py, elements))
}

#[getter]
Expand Down Expand Up @@ -159,27 +159,27 @@ impl NeoFoodClub {
}

#[getter]
fn current_odds<'a>(&self, py: Python<'a>) -> PyResult<&'a PyTuple> {
fn current_odds<'a>(&self, py: Python<'a>) -> PyResult<Bound<'a, PyTuple>> {
let elements = self.inner.current_odds();
Ok(PyTuple::new(py, elements))
Ok(PyTuple::new_bound(py, elements))
}

#[getter]
fn custom_odds<'a>(&self, py: Python<'a>) -> PyResult<&'a PyTuple> {
fn custom_odds<'a>(&self, py: Python<'a>) -> PyResult<Bound<'a, PyTuple>> {
let elements = self.inner.custom_odds();
Ok(PyTuple::new(py, elements))
Ok(PyTuple::new_bound(py, elements))
}

#[getter]
fn opening_odds<'a>(&self, py: Python<'a>) -> PyResult<&'a PyTuple> {
fn opening_odds<'a>(&self, py: Python<'a>) -> PyResult<Bound<'a, PyTuple>> {
let elements = self.inner.opening_odds();
Ok(PyTuple::new(py, elements))
Ok(PyTuple::new_bound(py, elements))
}

#[getter]
fn pirates<'a>(&self, py: Python<'a>) -> PyResult<&'a PyTuple> {
fn pirates<'a>(&self, py: Python<'a>) -> PyResult<Bound<'a, PyTuple>> {
let elements = self.inner.pirates();
Ok(PyTuple::new(py, elements))
Ok(PyTuple::new_bound(py, elements))
}

#[getter]
Expand All @@ -206,11 +206,11 @@ impl NeoFoodClub {
}

#[getter]
fn foods<'a>(&self, py: Python<'a>) -> PyResult<Option<&'a PyTuple>> {
fn foods<'a>(&self, py: Python<'a>) -> PyResult<Option<Bound<'a, PyTuple>>> {
let elements = self.inner.foods();

match elements {
Some(e) => Ok(Some(PyTuple::new(py, e))),
Some(e) => Ok(Some(PyTuple::new_bound(py, e))),
None => Ok(None),
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/pirates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ impl Pirate {
&self,
nfc: &NeoFoodClub,
py: Python<'a>,
) -> PyResult<Option<&'a PyTuple>> {
) -> PyResult<Option<Bound<'a, PyTuple>>> {
let elements = self.inner.positive_foods(&nfc.inner);

match elements {
Some(foods) => Ok(Some(PyTuple::new(py, foods))),
Some(foods) => Ok(Some(PyTuple::new_bound(py, foods))),
None => Ok(None),
}
}
Expand All @@ -151,11 +151,11 @@ impl Pirate {
&self,
nfc: &NeoFoodClub,
py: Python<'a>,
) -> PyResult<Option<&'a PyTuple>> {
) -> PyResult<Option<Bound<'a, PyTuple>>> {
let elements = self.inner.negative_foods(&nfc.inner);

match elements {
Some(foods) => Ok(Some(PyTuple::new(py, foods))),
Some(foods) => Ok(Some(PyTuple::new_bound(py, foods))),
None => Ok(None),
}
}
Expand Down

0 comments on commit a104145

Please sign in to comment.