MCPcopy Create free account
hub / github.com/InkSha/rust-tutorial / create_todo

Function create_todo

src/todo/create.rs:3–85  ·  view source on GitHub ↗
(todos: &mut Vec<TodoItem>, title: Option<String>, content: Option<String>)

Source from the content-addressed store, hash-verified

1use crate::todo::core::TodoItem;
2
3pub fn create_todo(todos: &mut Vec<TodoItem>, title: Option<String>, content: Option<String>) {
4 let mut inputs: Vec<String> = Vec::new();
5
6 if let Some(arg_title) = title {
7 if !arg_title.is_empty() {
8 inputs.push(arg_title);
9 }
10 }
11
12 if let Some(arg_content) = content {
13 if !arg_content.is_empty() {
14 inputs.push(arg_content);
15 }
16 }
17
18 let mut ok = inputs.len() == 0;
19
20 while ok {
21 let len = inputs.len();
22
23 if len == 0 {
24 println!("Please input todo title");
25
26 let mut title = String::new();
27
28 std::io::stdin()
29 .read_line(&mut title)
30 .expect("read line failed");
31
32 if title.is_empty() {
33 continue;
34 }
35
36 inputs.push(title.trim().to_string());
37 } else if len == 1 {
38 println!("Please input todo content");
39
40 let mut content = String::new();
41
42 std::io::stdin()
43 .read_line(&mut content)
44 .expect("read line failed");
45
46 if content.is_empty() {
47 continue;
48 }
49
50 inputs.push(content.trim().to_string());
51 } else {
52 println!("title: [{}]", inputs[0].clone());
53 println!("content: [{}]", inputs[1].clone());
54 println!("Are you sure to create this todo? (y/n)");
55
56 let mut sure = String::new();
57 std::io::stdin()
58 .read_line(&mut sure)
59 .expect("read line failed");
60

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected