summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index bbaa08c..588f4e9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -17,6 +17,7 @@ use adblock::engine::Engine as RustEngine;
17use pyo3::class::PyObjectProtocol; 17use pyo3::class::PyObjectProtocol;
18use pyo3::exceptions::ValueError as PyValueError; 18use pyo3::exceptions::ValueError as PyValueError;
19use pyo3::prelude::*; 19use pyo3::prelude::*;
20use pyo3::types::PyBytes;
20use pyo3::PyErr; 21use pyo3::PyErr;
21 22
22use std::collections::HashMap; 23use 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)