Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pyo3 #44

Merged
merged 4 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.22.6", features = ["extension-module", "abi3-py311", "chrono", "chrono-tz"] }
pyo3 = { version = "0.23.0", features = ["extension-module", "abi3-py311", "chrono", "chrono-tz"] }
neofoodclub = { path = "./neofoodclub_rs" }
chrono = "0.4.38"
chrono-tz = "0.10.0"
Expand Down
10 changes: 4 additions & 6 deletions src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ impl Arena {

#[getter]
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_bound(py, foods))),
match self.inner.foods {
Some(foods) => Ok(Some(PyTuple::new(py, foods)?)),
None => Ok(None),
}
}
Expand All @@ -55,7 +53,7 @@ impl Arena {
#[getter]
fn pirate_ids<'a>(&self, py: Python<'a>) -> PyResult<Bound<'a, PyTuple>> {
let elements = &self.inner.ids();
Ok(PyTuple::new_bound(py, elements))
PyTuple::new(py, elements)
}

#[getter]
Expand Down Expand Up @@ -180,7 +178,7 @@ impl Arenas {
.iter()
.map(|a| a.pirate_ids(py).expect("failed to get pirate ids"))
.collect();
Ok(PyTuple::new_bound(py, elements))
PyTuple::new(py, elements)
}

#[getter]
Expand Down
10 changes: 5 additions & 5 deletions src/bets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Bets {
let elements = &self.inner.bet_amounts;

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

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

#[getter]
Expand Down Expand Up @@ -104,12 +104,12 @@ impl Bets {
#[getter]
fn indices<'a>(&self, py: Python<'a>) -> PyResult<Bound<'a, PyTuple>> {
let indicies = self.inner.get_indices();
let py_indicies: Vec<Bound<'a, PyTuple>> = indicies
let py_indicies: Result<Vec<Bound<'a, PyTuple>>, PyErr> = indicies
.iter()
.map(|index| PyTuple::new_bound(py, index))
.map(|index| PyTuple::new(py, index))
.collect();

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

fn net_expected(&self, nfc: &NeoFoodClub) -> f64 {
Expand Down
21 changes: 10 additions & 11 deletions src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Math {
#[staticmethod]
fn binary_to_indices(py: Python<'_>, binary: u32) -> PyResult<Bound<'_, PyTuple>> {
let elements = neofoodclub::math::binary_to_indices(binary);
Ok(PyTuple::new_bound(py, elements))
PyTuple::new(py, elements)
}

#[staticmethod]
Expand All @@ -40,7 +40,7 @@ impl Math {
bets_hash: &'a str,
) -> PyResult<Bound<'a, PyTuple>> {
let elements = neofoodclub::math::bets_hash_to_bet_indices(bets_hash);
Ok(PyTuple::new_bound(py, elements))
PyTuple::new(py, elements)
}

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

#[staticmethod]
Expand All @@ -68,7 +68,7 @@ impl Math {
bets_hash: &'a str,
) -> PyResult<Bound<'a, PyTuple>> {
let elements = neofoodclub::math::bets_hash_to_bet_binaries(bets_hash);
Ok(PyTuple::new_bound(py, elements))
PyTuple::new(py, elements)
}

#[staticmethod]
Expand All @@ -82,7 +82,7 @@ impl Math {
bets_indices: Vec<[u8; 5]>,
) -> PyResult<Bound<'_, PyTuple>> {
let elements = neofoodclub::math::bets_indices_to_bet_binaries(bets_indices);
Ok(PyTuple::new_bound(py, elements))
PyTuple::new(py, elements)
}

#[staticmethod]
Expand All @@ -92,13 +92,12 @@ impl Math {
bet_odds: Vec<u32>,
probabilities: [[f64; 5]; 5],
) -> PyResult<Bound<'_, 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();
let py_structs = neofoodclub::math::build_chance_objects(&bets, &bet_odds, probabilities)
.into_iter()
.map(|chance| Chance::from(chance).into_pyobject(py))
.collect::<Result<Vec<_>, _>>()?;

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

#[staticmethod]
Expand Down
14 changes: 8 additions & 6 deletions src/nfc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub struct NeoFoodClub {
pub inner: neofoodclub::nfc::NeoFoodClub,
}

unsafe impl Sync for NeoFoodClub {}

fn convert_probability_model_int_to_enum(
probability_model: Option<u8>,
) -> Option<neofoodclub::nfc::ProbabilityModel> {
Expand Down Expand Up @@ -132,7 +134,7 @@ impl NeoFoodClub {
#[getter]
fn winners<'a>(&self, py: Python<'a>) -> PyResult<Bound<'a, PyTuple>> {
let elements = self.inner.winners();
Ok(PyTuple::new_bound(py, elements))
PyTuple::new(py, elements)
}

#[getter]
Expand Down Expand Up @@ -163,25 +165,25 @@ impl NeoFoodClub {
#[getter]
fn current_odds<'a>(&self, py: Python<'a>) -> PyResult<Bound<'a, PyTuple>> {
let elements = self.inner.current_odds();
Ok(PyTuple::new_bound(py, elements))
PyTuple::new(py, elements)
}

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

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

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

#[getter]
Expand Down Expand Up @@ -212,7 +214,7 @@ impl NeoFoodClub {
let elements = self.inner.foods();

match elements {
Some(e) => Ok(Some(PyTuple::new_bound(py, e))),
Some(e) => Ok(Some(PyTuple::new(py, e)?)),
None => Ok(None),
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/pirates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl Pirate {
let elements = self.inner.positive_foods(&nfc.inner);

match elements {
Some(foods) => Ok(Some(PyTuple::new_bound(py, foods))),
Some(foods) => Ok(Some(PyTuple::new(py, foods)?)),
None => Ok(None),
}
}
Expand All @@ -156,7 +156,7 @@ impl Pirate {
let elements = self.inner.negative_foods(&nfc.inner);

match elements {
Some(foods) => Ok(Some(PyTuple::new_bound(py, foods))),
Some(foods) => Ok(Some(PyTuple::new(py, foods)?)),
None => Ok(None),
}
}
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading