Rename BytesExtractor method names to reflect their actions

This commit is contained in:
Samuele Maci 2019-10-11 17:59:48 +02:00
parent 681996da38
commit 9ff41fcd3b
2 changed files with 10 additions and 10 deletions

View File

@ -13,14 +13,14 @@ impl BytesExtractor {
obj.init({ BytesExtractor {} });
}
pub fn to_vec(&mut self, bytes: &PyBytes) -> PyResult<usize> {
pub fn from_bytes(&mut self, bytes: &PyBytes) -> PyResult<usize> {
let byte_vec: Vec<u8> = bytes.extract().unwrap();
Ok(byte_vec.len())
}
pub fn to_str(&mut self, bytes: &PyString) -> PyResult<usize> {
let byte_str: String = bytes.extract().unwrap();
Ok(byte_str.len())
pub fn from_str(&mut self, string: &PyString) -> PyResult<usize> {
let rust_string: String = string.extract().unwrap();
Ok(rust_string.len())
}
}

View File

@ -26,13 +26,13 @@ def test_pybuffer_doesnot_leak_memory():
message_b = b'\\(-"-;) Praying that memory leak would not happen..'
message_s = '\\(-"-;) Praying that memory leak would not happen..'
def to_vec():
def from_bytes():
for i in range(N):
extractor.to_vec(message_b)
extractor.from_bytes(message_b)
def to_str():
def from_str():
for i in range(N):
extractor.to_str(message_s)
extractor.from_str(message_s)
assert memory_diff(to_vec) == 0
assert memory_diff(to_str) == 0
assert memory_diff(from_bytes) == 0
assert memory_diff(from_str) == 0