diff options
| author | Árni Dagur <agudmundsson@fc-md.umd.edu> | 2020-06-21 18:20:20 -0400 |
|---|---|---|
| committer | Árni Dagur <agudmundsson@fc-md.umd.edu> | 2020-06-21 18:20:20 -0400 |
| commit | 019b5b35ebf07022e37d6b8715820b439a18f32b (patch) | |
| tree | 9b4cc5cbe5b50dc9d748ca23a224dc31237ca903 /src | |
| parent | 4bb4cb4e6c49226740e80a8dd1639274e0719b53 (diff) | |
Correct return type for the serialize method
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 11 |
1 files changed, 9 insertions, 2 deletions
| @@ -17,6 +17,7 @@ use adblock::engine::Engine as RustEngine; | |||
| 17 | use pyo3::class::PyObjectProtocol; | 17 | use pyo3::class::PyObjectProtocol; |
| 18 | use pyo3::exceptions::ValueError as PyValueError; | 18 | use pyo3::exceptions::ValueError as PyValueError; |
| 19 | use pyo3::prelude::*; | 19 | use pyo3::prelude::*; |
| 20 | use pyo3::types::PyBytes; | ||
| 20 | use pyo3::PyErr; | 21 | use pyo3::PyErr; |
| 21 | 22 | ||
| 22 | use std::collections::HashMap; | 23 | use std::collections::HashMap; |
| @@ -348,7 +349,13 @@ impl Engine { | |||
| 348 | /// Serialize this blocking engine to bytes. They can then be deserialized | 349 | /// Serialize this blocking engine to bytes. They can then be deserialized |
| 349 | /// using `deserialize()` to get the same engine again. | 350 | /// using `deserialize()` to get the same engine again. |
| 350 | #[text_signature = "($self)"] | 351 | #[text_signature = "($self)"] |
| 351 | pub fn serialize(&mut self) -> PyResult<Vec<u8>> { | 352 | pub fn serialize<'p>(&mut self, py: Python<'p>) -> PyResult<&'p PyBytes> { |
| 353 | let bytes = self.serialize_inner()?; | ||
| 354 | let py_bytes = PyBytes::new(py, &bytes); | ||
| 355 | Ok(py_bytes) | ||
| 356 | } | ||
| 357 | |||
| 358 | fn serialize_inner(&mut self) -> PyResult<Vec<u8>> { | ||
| 352 | let result = self.engine.serialize(); | 359 | let result = self.engine.serialize(); |
| 353 | match result { | 360 | match result { |
| 354 | Ok(x) => Ok(x), | 361 | Ok(x) => Ok(x), |
| @@ -364,7 +371,7 @@ impl Engine { | |||
| 364 | /// again. | 371 | /// again. |
| 365 | #[text_signature = "($self, file)"] | 372 | #[text_signature = "($self, file)"] |
| 366 | pub fn serialize_to_file(&mut self, file: &str) -> PyResult<()> { | 373 | pub fn serialize_to_file(&mut self, file: &str) -> PyResult<()> { |
| 367 | let data = self.serialize()?; | 374 | let data = self.serialize_inner()?; |
| 368 | let mut fd = fs::OpenOptions::new() | 375 | let mut fd = fs::OpenOptions::new() |
| 369 | .create(true) | 376 | .create(true) |
| 370 | .truncate(true) | 377 | .truncate(true) |
