Loading Cargo.lock +2 −0 Original line number Diff line number Diff line Loading @@ -1992,7 +1992,9 @@ dependencies = [ name = "pipe-py" version = "0.0.1" dependencies = [ "pipe-lib", "pyo3", "rand", ] [[package]] Loading pipe-py/Cargo.toml +3 −1 Original line number Diff line number Diff line Loading @@ -10,4 +10,6 @@ name = "pipe" crate-type = ["cdylib"] [dependencies] pyo3 = { version = "0.22.2", features = ["extension-module"] } No newline at end of file pipe-lib = { path = "../pipe-lib" } pyo3 = { version = "0.22.2", features = ["abi3-py310", "extension-module"] } rand = "0.8.5" pipe-py/src/lib.rs +44 −1 Original line number Diff line number Diff line // use pyo3::prelude::*; use pyo3::prelude::*; use pipe_lib::add_forward_slash as _add_forward_slash; use rand::Rng; use std::cmp::Ordering; use std::{io, path::PathBuf}; #[pyfunction] fn add_forward_slash(value: &str) -> String { let path = PathBuf::from(value); _add_forward_slash(path).into_os_string().into_string().unwrap() } #[pyfunction] fn guess_the_number() { println!("Guess the number!"); let secret_number = rand::thread_rng().gen_range(1..101); loop { println!("Please input your guess."); let mut guess = String::new(); io::stdin() .read_line(&mut guess) .expect("Failed to read line"); let guess: u32 = match guess.trim().parse() { Ok(num) => num, Err(_) => continue, }; println!("You guessed: {}", guess); match guess.cmp(&secret_number) { Ordering::Less => println!("Too small!"), Ordering::Greater => println!("Too big!"), Ordering::Equal => { println!("You win!"); break; } } } } #[pymodule] fn pipe(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_function(wrap_pyfunction!(add_forward_slash, m)?)?; m.add_function(wrap_pyfunction!(guess_the_number, m)?)?; Ok(()) } Loading
Cargo.lock +2 −0 Original line number Diff line number Diff line Loading @@ -1992,7 +1992,9 @@ dependencies = [ name = "pipe-py" version = "0.0.1" dependencies = [ "pipe-lib", "pyo3", "rand", ] [[package]] Loading
pipe-py/Cargo.toml +3 −1 Original line number Diff line number Diff line Loading @@ -10,4 +10,6 @@ name = "pipe" crate-type = ["cdylib"] [dependencies] pyo3 = { version = "0.22.2", features = ["extension-module"] } No newline at end of file pipe-lib = { path = "../pipe-lib" } pyo3 = { version = "0.22.2", features = ["abi3-py310", "extension-module"] } rand = "0.8.5"
pipe-py/src/lib.rs +44 −1 Original line number Diff line number Diff line // use pyo3::prelude::*; use pyo3::prelude::*; use pipe_lib::add_forward_slash as _add_forward_slash; use rand::Rng; use std::cmp::Ordering; use std::{io, path::PathBuf}; #[pyfunction] fn add_forward_slash(value: &str) -> String { let path = PathBuf::from(value); _add_forward_slash(path).into_os_string().into_string().unwrap() } #[pyfunction] fn guess_the_number() { println!("Guess the number!"); let secret_number = rand::thread_rng().gen_range(1..101); loop { println!("Please input your guess."); let mut guess = String::new(); io::stdin() .read_line(&mut guess) .expect("Failed to read line"); let guess: u32 = match guess.trim().parse() { Ok(num) => num, Err(_) => continue, }; println!("You guessed: {}", guess); match guess.cmp(&secret_number) { Ordering::Less => println!("Too small!"), Ordering::Greater => println!("Too big!"), Ordering::Equal => { println!("You win!"); break; } } } } #[pymodule] fn pipe(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_function(wrap_pyfunction!(add_forward_slash, m)?)?; m.add_function(wrap_pyfunction!(guess_the_number, m)?)?; Ok(()) }