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