INNER CODE UNIT · Rust

text_guard

bminixhofer/nlprule · python/src/lib.rs:70

fn text_guard<F, O>(py: Python, text_or_texts: PyObject, f: F) -> PyResult<PyObject>
where
    F: Fn(String) -> PyResult<O>,
    O: ToPyObject,
{
    let text_or_texts = text_or_texts.as_ref(py);
    let is_iterable =
        text_or_texts.hasattr("__iter__")? && !text_or_texts.is_instance::<PyString>()?;

    let texts: Vec<String> = if is_iterable {
        text_or_texts.extract()?
    } else {
        vec![text_or_texts.extract()?]
    };

    let mut output = Vec::new();

    for text in texts {

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…