Quick improvement over python bindings

This commit is contained in:
Anthony MOI
2019-11-01 16:08:10 -04:00
parent 5d37cfde7f
commit 8448d50e6f
4 changed files with 9 additions and 8 deletions

View File

@ -1,4 +1,5 @@
extern crate tokenizers as tk; extern crate tokenizers as tk;
use pyo3::prelude::*; use pyo3::prelude::*;
use pyo3::wrap_pyfunction; use pyo3::wrap_pyfunction;
@ -6,8 +7,7 @@ use pyo3::wrap_pyfunction;
/// Tokenize /// Tokenize
fn tokenize(a: String) -> PyResult<Vec<u32>> { fn tokenize(a: String) -> PyResult<Vec<u32>> {
println!("Tokenize in rust"); println!("Tokenize in rust");
tk::test(); Ok(tk::tokenize(&a))
Ok(vec![1, 2, 3])
} }
#[pymodule] #[pymodule]
@ -20,6 +20,6 @@ fn tokenizers(py: Python, m: &PyModule) -> PyResult<()> {
mod tests { mod tests {
#[test] #[test]
fn it_works() { fn it_works() {
assert_eq!(2 + 2, 4); assert_eq!(tk::tokenize("Hey man!"), vec![1, 2, 3]);
} }
} }

2
tokenizers/Cargo.lock generated
View File

@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
[[package]] [[package]]
name = "tokenizers" name = "tokenizers-lib"
version = "0.1.0" version = "0.1.0"

View File

@ -1,7 +1,8 @@
/// This is the CLI binary for the Tokenizers project /// This is the CLI binary for the Tokenizers project
use tokenizers::test; use tokenizers;
fn main() { fn main() {
println!("Hello, world!"); println!("Hello, world!");
test(); let s = "Hey man!";
println!("Tokenizing {:?} gives {:?}", s, tokenizers::tokenize(&s));
} }

View File

@ -1,3 +1,3 @@
pub fn test() { pub fn tokenize(s: &str) -> Vec<u32> {
println!("Test"); vec![1, 2, 3]
} }