INNER CODE UNIT · Rust

Ok

RyanCodrai/turbovec · turbovec-python/src/lib.rs:248

    if let Ok(b) = obj.cast::<PyBytes>() {
        return Ok(b.as_bytes().to_vec());
    }
    if let Ok(b) = obj.cast::<pyo3::types::PyByteArray>() {
        return Ok(b.to_vec());
    }
    Err(pyo3::exceptions::PyTypeError::new_err(format!(
        "{name} must be a bytes-like object (bytes or bytearray), got {}",
        type_name(obj),
    )))
}

/// Map an `io::Error` from `from_bytes` to Python. Unlike [`load_err`]
/// there is no path to blame, and the input is an in-memory value —
/// so corrupt bytes raise `ValueError` (like other malformed-value
/// arguments) rather than `OSError`.
fn from_bytes_err(e: std::io::Error) -> PyErr {
    pyo3::exceptions::PyValueError::new_err(e.to_string())

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…