Python - Add Encoding length

This commit is contained in:
Anthony MOI
2020-02-18 18:24:13 -05:00
parent 0dc857ea8c
commit d8a73c89a7

View File

@ -4,7 +4,7 @@ use crate::error::PyError;
use pyo3::exceptions; use pyo3::exceptions;
use pyo3::prelude::*; use pyo3::prelude::*;
use pyo3::types::*; use pyo3::types::*;
use pyo3::{PyMappingProtocol, PyObjectProtocol}; use pyo3::{PyMappingProtocol, PyObjectProtocol, PySequenceProtocol};
use tk::tokenizer::PaddingDirection; use tk::tokenizer::PaddingDirection;
fn get_range(item: PyObject, max_len: usize) -> PyResult<std::ops::Range<usize>> { fn get_range(item: PyObject, max_len: usize) -> PyResult<std::ops::Range<usize>> {
@ -133,6 +133,13 @@ impl PyObjectProtocol for Encoding {
} }
} }
#[pyproto]
impl PySequenceProtocol for Encoding {
fn __len__(self) -> PyResult<usize> {
Ok(self.encoding.get_ids().len())
}
}
#[pymethods] #[pymethods]
impl Encoding { impl Encoding {
#[getter] #[getter]