Skip to content
This repository was archived by the owner on Oct 22, 2020. It is now read-only.

Commit 9eb0eb1

Browse files
Max LarssonMax Larsson
authored andcommitted
Changed program to be a library instead of an executable
0 parents  commit 9eb0eb1

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
**/*.rs.bk

Cargo.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "python-input"
3+
version = "0.1.0"
4+
authors = ["student"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# python-input

src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use std::io::{stdin, stdout, Write};
2+
3+
pub fn input(input_string: &str) -> String {
4+
print!("{}", input_string);
5+
let mut input = String::new();
6+
7+
stdout().flush().expect("Failed to flush stdout!");
8+
stdin().read_line(&mut input).expect("Failed to read line");
9+
10+
input.pop();
11+
12+
return input;
13+
}
14+
15+
#[cfg(test)]
16+
mod tests {
17+
#[test]
18+
fn it_works() {
19+
assert_eq!(2 + 2, 4);
20+
}
21+
}

0 commit comments

Comments
 (0)