|
1 | 1 | [
|
| 2 | + { |
2 | 3 | {
|
3 | 4 | "categoryName": "Terminal Output",
|
4 | 5 | "snippets": [
|
|
14 | 15 | "author": "James-Beans"
|
15 | 16 | }
|
16 | 17 | ]
|
17 |
| - }, |
18 |
| - { |
19 |
| - "categoryName": "String Manipulation", |
20 |
| - "snippets": [ |
21 |
| - { |
22 |
| - "title": "Capitalize String", |
23 |
| - "description": "Makes the first letter of a string uppercase.", |
24 |
| - "code": [ |
25 |
| - "fn capitalized(str: &str) -> String {", |
26 |
| - " let mut chars = str.chars();", |
27 |
| - " match chars.next() {", |
28 |
| - " None => String::new(),", |
29 |
| - " Some(f) => f.to_uppercase().chain(chars).collect(),", |
30 |
| - " }", |
31 |
| - "}", |
32 |
| - "", |
33 |
| - "// Usage:", |
34 |
| - "assert_eq!(capitalized(\"lower_case\"), \"Lower_case\")" |
35 |
| - ], |
36 |
| - "tags": ["rust", "string", "capitalize", "utility"], |
37 |
| - "author": "Mathys-Gasnier" |
38 |
| - } |
39 |
| - ] |
40 |
| - }, |
41 |
| - { |
42 |
| - "categoryName": "File Handling", |
43 |
| - "snippets": [ |
44 |
| - { |
45 |
| - "title": "Read File Lines", |
46 |
| - "description": "Reads all lines from a file and returns them as a vector of strings.", |
47 |
| - "code": [ |
48 |
| - "fn read_lines(file_name: &str) -> std::io::Result<Vec<String>>", |
49 |
| - " Ok(", |
50 |
| - " std::fs::read_to_string(file_name)?", |
51 |
| - " .lines()", |
52 |
| - " .map(String::from)", |
53 |
| - " .collect()", |
54 |
| - " )", |
55 |
| - "}", |
56 |
| - "", |
57 |
| - "// Usage:", |
58 |
| - "let lines = read_lines(\"path/to/file.txt\").expect(\"Failed to read lines from file\")" |
59 |
| - ], |
60 |
| - "tags": ["rust", "file", "read", "utility"], |
61 |
| - "author": "Mathys-Gasnier" |
62 |
| - }, |
63 |
| - { |
64 |
| - "title": "Find Files", |
65 |
| - "description": "Finds all files of the specified extension within a given directory.", |
66 |
| - "code": [ |
67 |
| - "fn find_files(directory: &str, file_type: &str) -> std::io::Result<Vec<std::path::PathBuf>> {", |
68 |
| - " let mut result = vec![];", |
69 |
| - "", |
70 |
| - " for entry in std::fs::read_dir(directory)? {", |
71 |
| - " let dir = entry?;", |
72 |
| - " let path = dir.path();", |
73 |
| - " if dir.file_type().is_ok_and(|t| !t.is_file()) &&", |
74 |
| - " path.extension().is_some_and(|ext| ext != file_type) {", |
75 |
| - " continue;", |
76 |
| - " }", |
77 |
| - " result.push(path)", |
78 |
| - " }", |
79 |
| - "", |
80 |
| - " Ok(result)", |
81 |
| - "}", |
82 |
| - "", |
83 |
| - "// Usage:", |
84 |
| - "let files = find_files(\"/path/to/your/directory\", \".pdf\")" |
85 |
| - ], |
86 |
| - "tags": ["rust", "file", "search"], |
87 |
| - "author": "Mathys-Gasnier" |
88 |
| - } |
89 |
| - ] |
90 |
| - } |
| 18 | +}, |
| 19 | +{ |
| 20 | + "categoryName": "String Manipulation", |
| 21 | + "snippets": [ |
| 22 | + { |
| 23 | + "title": "Capitalize String", |
| 24 | + "description": "Makes the first letter of a string uppercase.", |
| 25 | + "code": [ |
| 26 | + "fn capitalized(str: &str) -> String {", |
| 27 | + " let mut chars = str.chars();", |
| 28 | + " match chars.next() {", |
| 29 | + " None => String::new(),", |
| 30 | + " Some(f) => f.to_uppercase().chain(chars).collect(),", |
| 31 | + " }", |
| 32 | + "}", |
| 33 | + "", |
| 34 | + "// Usage:", |
| 35 | + "assert_eq!(capitalized(\"lower_case\"), \"Lower_case\")" |
| 36 | + ], |
| 37 | + "tags": ["rust", "string", "capitalize", "utility"], |
| 38 | + "author": "Mathys-Gasnier" |
| 39 | + } |
| 40 | + ] |
| 41 | + }, |
| 42 | + { |
| 43 | + "categoryName": "File Handling", |
| 44 | + "snippets": [ |
| 45 | + { |
| 46 | + "title": "Read File Lines", |
| 47 | + "description": "Reads all lines from a file and returns them as a vector of strings.", |
| 48 | + "code": [ |
| 49 | + "fn read_lines(file_name: &str) -> std::io::Result<Vec<String>>", |
| 50 | + " Ok(", |
| 51 | + " std::fs::read_to_string(file_name)?", |
| 52 | + " .lines()", |
| 53 | + " .map(String::from)", |
| 54 | + " .collect()", |
| 55 | + " )", |
| 56 | + "}", |
| 57 | + "", |
| 58 | + "// Usage:", |
| 59 | + "let lines = read_lines(\"path/to/file.txt\").expect(\"Failed to read lines from file\")" |
| 60 | + ], |
| 61 | + "tags": ["rust", "file", "read", "utility"], |
| 62 | + "author": "Mathys-Gasnier" |
| 63 | + }, |
| 64 | + { |
| 65 | + "title": "Find Files", |
| 66 | + "description": "Finds all files of the specified extension within a given directory.", |
| 67 | + "code": [ |
| 68 | + "fn find_files(directory: &str, file_type: &str) -> std::io::Result<Vec<std::path::PathBuf>> {", |
| 69 | + " let mut result = vec![];", |
| 70 | + "", |
| 71 | + " for entry in std::fs::read_dir(directory)? {", |
| 72 | + " let dir = entry?;", |
| 73 | + " let path = dir.path();", |
| 74 | + " if dir.file_type().is_ok_and(|t| !t.is_file()) &&", |
| 75 | + " path.extension().is_some_and(|ext| ext != file_type) {", |
| 76 | + " continue;", |
| 77 | + " }", |
| 78 | + " result.push(path)", |
| 79 | + " }", |
| 80 | + "", |
| 81 | + " Ok(result)", |
| 82 | + "}", |
| 83 | + "", |
| 84 | + "// Usage:", |
| 85 | + "let files = find_files(\"/path/to/your/directory\", \".pdf\")" |
| 86 | + ], |
| 87 | + "tags": ["rust", "file", "search"], |
| 88 | + "author": "Mathys-Gasnier" |
| 89 | + } |
| 90 | + ] |
| 91 | + } |
91 | 92 | ]
|
0 commit comments