archive
/
svg-hush-py
Archived
1
Fork 0
This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
svg-hush-py/src/lib.rs

23 lines
610 B
Rust

use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;
use std::error::Error;
#[pyfunction]
fn filter(py: Python, input: String) -> PyResult<String> {
let f = svg_hush::Filter::new();
let mut out = Vec::new();
let result = py.allow_threads(|| f.filter(&mut input.as_bytes(), &mut out));
match result {
Ok(()) => Ok(String::from_utf8_lossy(&out).to_string()),
Err(e) => Err(PyValueError::new_err(e.source().unwrap().to_string())),
}
}
#[pymodule]
fn svg_hush(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(filter, m)?)?;
Ok(())
}