INNER CODE UNIT · Rust

__setstate__

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

    pub fn __setstate__(&mut self, py: Python, state: PyObject) -> PyResult<()> {
        match state.extract::<&PyBytes>(py) {
            Ok(s) => {
                self.tokenizer = bincode::deserialize(s.as_bytes()).map_err(|_| {
                    PyValueError::new_err("deserializing state with `bincode` failed")
                })?;
                Ok(())
            }
            Err(e) => Err(e),
        }
    }

    pub fn __getstate__(&self, py: Python) -> PyResult<PyObject> {
        Ok(PyBytes::new(
            py,
            &bincode::serialize(&self.tokenizer)
                .map_err(|_| PyValueError::new_err("serializing state with `bincode` failed"))?,
        )

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…