Skip to content

Commit

Permalink
Merge pull request #6 from emattiza/feat/add-docstrings
Browse files Browse the repository at this point in the history
chore: add docstrings to methods and module
  • Loading branch information
emattiza committed Sep 19, 2023
2 parents 00d37db + f7103cc commit dec0804
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use chardetng::EncodingDetector;
use pyo3::prelude::*;

/// Detect a character set from an array of bytes
/// Returns the name as found by chardet-ng
#[pyfunction]
fn detect_rs_enc_name(a: &[u8]) -> PyResult<&str> {
let mut detector = EncodingDetector::new();
Expand All @@ -10,6 +12,8 @@ fn detect_rs_enc_name(a: &[u8]) -> PyResult<&str> {
Ok(rust_name)
}

/// Detect a character set from an array of bytes
/// Returns the name as found by codecs.lookup from python
#[pyfunction]
fn detect_codec(a: &[u8]) -> PyResult<PyObject> {
let enc_rs_name = detect_rs_enc_name(a)?;
Expand All @@ -21,7 +25,8 @@ fn detect_codec(a: &[u8]) -> PyResult<PyObject> {
lookup_codec
}

/// A Python module implemented in Rust.
/// Chardet-NG support in python from rust
/// Enables character set detection provided a byte sample
#[pymodule]
fn rs_chardet(_py: Python, m: &PyModule) -> PyResult<()> {
m.add("__version__", env!("CARGO_PKG_VERSION"))?;
Expand Down

0 comments on commit dec0804

Please sign in to comment.