generated from PlexSheep/baserepo
python bintols
cargo devel CI / cargo CI (push) Successful in 3m40s
Details
cargo devel CI / cargo CI (push) Successful in 3m40s
Details
This commit is contained in:
parent
10ec77aef0
commit
6d4e82b0b7
|
@ -0,0 +1,56 @@
|
|||
use pyo3::prelude::*;
|
||||
|
||||
use libpt::bintols as origin;
|
||||
|
||||
mod display {
|
||||
use pyo3::prelude::*;
|
||||
|
||||
use libpt::bintols::display as origin;
|
||||
|
||||
#[pyfunction]
|
||||
pub fn bytes_to_bin(data: &[u8]) -> String {
|
||||
origin::bytes_to_bin(data)
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
pub fn byte_bit_display(data: usize) -> String {
|
||||
origin::byte_bit_display(data)
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
pub fn humanbytes(total: u128) -> String {
|
||||
origin::humanbytes(total)
|
||||
}
|
||||
|
||||
/// implement a python module in Rust
|
||||
pub fn submodule(py: Python, parent: &PyModule) -> PyResult<()> {
|
||||
let module = PyModule::new(py, "display")?;
|
||||
|
||||
module.add_function(wrap_pyfunction!(bytes_to_bin, module)?)?;
|
||||
module.add_function(wrap_pyfunction!(byte_bit_display, module)?)?;
|
||||
module.add_function(wrap_pyfunction!(humanbytes, module)?)?;
|
||||
|
||||
parent.add_submodule(module)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// implement a python module in Rust
|
||||
pub fn submodule(py: Python, parent: &PyModule) -> PyResult<()> {
|
||||
let module = PyModule::new(py, "bintols")?;
|
||||
|
||||
// binary constants
|
||||
module.add("KIBI", origin::KIBI)?;
|
||||
module.add("MEBI", origin::MEBI)?;
|
||||
module.add("GIBI", origin::GIBI)?;
|
||||
module.add("TEBI", origin::TEBI)?;
|
||||
module.add("PEBI", origin::PEBI)?;
|
||||
module.add("EXBI", origin::EXBI)?;
|
||||
module.add("ZEBI", origin::ZEBI)?;
|
||||
module.add("YOBI", origin::YOBI)?;
|
||||
|
||||
display::submodule(py, module)?;
|
||||
|
||||
parent.add_submodule(module)?;
|
||||
Ok(())
|
||||
}
|
|
@ -4,6 +4,8 @@
|
|||
mod core;
|
||||
#[cfg(feature = "log")]
|
||||
mod log;
|
||||
#[cfg(feature = "bintols")]
|
||||
mod bintols;
|
||||
|
||||
use pyo3::prelude::*;
|
||||
|
||||
|
@ -20,6 +22,9 @@ fn libpt_py(py: Python, m: &PyModule) -> PyResult<()> {
|
|||
m.add_function(wrap_pyfunction!(version, m)?)?;
|
||||
#[cfg(feature = "core")]
|
||||
core::submodule(py, m)?;
|
||||
#[cfg(feature = "log")]
|
||||
log::submodule(py, m)?;
|
||||
#[cfg(feature = "bintols")]
|
||||
bintols::submodule(py, m)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
Reference in New Issue