Skip to content

Commit

Permalink
fix: simplify Python wrapper types
Browse files Browse the repository at this point in the history
- Changed PyDataMap to use named field instead of tuple struct
- Made inner field public within crate
- Removed inner() method to avoid trait bound issues
- Updated function calls to use field directly
- Fixed PyO3 trait bound errors

This fixes the OkWrap trait bound error by simplifying the type
structure and avoiding method calls that expose Rust types to Python.
  • Loading branch information
dirvine committed Nov 29, 2024
1 parent af1b5d3 commit 507b90c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ use crate::{

#[pyclass]
#[derive(Clone)]
pub struct PyDataMap(crate::DataMap);
pub struct PyDataMap {
pub(crate) inner: crate::DataMap
}

#[pymethods]
impl PyDataMap {
#[new]
pub fn new() -> Self {
PyDataMap(crate::DataMap::new(vec![]))
PyDataMap {
inner: crate::DataMap::new(vec![])
}
}

pub fn __str__(&self) -> PyResult<String> {
Ok(format!("{:?}", self.0))
}

pub fn inner(&self) -> &crate::DataMap {
&self.0
Ok(format!("{:?}", self.inner))
}
}

impl From<crate::DataMap> for PyDataMap {
fn from(inner: crate::DataMap) -> Self {
PyDataMap(inner)
PyDataMap { inner }
}
}

Expand Down Expand Up @@ -112,7 +112,7 @@ fn encrypt_from_file(file_path: &str, output_dir: &str) -> PyResult<EncryptResul
fn decrypt_from_storage(data_map: &PyDataMap, output_file: &str, chunks_dir: &str) -> PyResult<()> {
let out_path = std::path::Path::new(output_file);
let chunks_path = std::path::Path::new(chunks_dir);
rust_decrypt_from_storage(data_map.inner(), out_path, |hash| {
rust_decrypt_from_storage(&data_map.inner, out_path, |hash| {
let chunk_path = chunks_path.join(hex::encode(hash));
std::fs::read(chunk_path)
.map(Bytes::from)
Expand All @@ -125,7 +125,7 @@ fn decrypt_from_storage(data_map: &PyDataMap, output_file: &str, chunks_dir: &st
fn streaming_decrypt_from_storage(data_map: &PyDataMap, output_file: &str, chunks_dir: &str) -> PyResult<()> {
let out_path = std::path::Path::new(output_file);
let chunks_path = std::path::Path::new(chunks_dir);
rust_streaming_decrypt_from_storage(data_map.inner(), out_path, |hashes| {
rust_streaming_decrypt_from_storage(&data_map.inner, out_path, |hashes| {
hashes.iter().map(|hash| {
let chunk_path = chunks_path.join(hex::encode(hash));
std::fs::read(chunk_path)
Expand Down

0 comments on commit 507b90c

Please sign in to comment.