|
924 | 924 | }
|
925 | 925 | ]
|
926 | 926 | },
|
| 927 | + { |
| 928 | + "language": "rust", |
| 929 | + "categoryName": "String Manipulation", |
| 930 | + "snippets": [ |
| 931 | + { |
| 932 | + "title": "Capitalize String", |
| 933 | + "description": "Makes the first letter of a string uppercase.", |
| 934 | + "code": [ |
| 935 | + "fn capitalized(str: &str) -> String {", |
| 936 | + " let mut chars = str.chars();", |
| 937 | + " match chars.next() {", |
| 938 | + " None => String::new(),", |
| 939 | + " Some(f) => f.to_uppercase().chain(chars).collect(),", |
| 940 | + " }", |
| 941 | + "}", |
| 942 | + "", |
| 943 | + "// Usage:", |
| 944 | + "assert_eq!(capitalized(\"lower_case\"), \"Lower_case\")" |
| 945 | + ], |
| 946 | + "tags": [ |
| 947 | + "rust", |
| 948 | + "string", |
| 949 | + "capitalize", |
| 950 | + "utility" |
| 951 | + ], |
| 952 | + "author": "Mathys-Gasnier" |
| 953 | + } |
| 954 | + ] |
| 955 | + }, |
| 956 | + { |
| 957 | + "language": "rust", |
| 958 | + "categoryName": "File Handling", |
| 959 | + "snippets": [ |
| 960 | + { |
| 961 | + "title": "Read File Lines", |
| 962 | + "description": "Reads all lines from a file and returns them as a vector of strings.", |
| 963 | + "code": [ |
| 964 | + "fn read_lines(file_name: &str) -> std::io::Result<Vec<String>>", |
| 965 | + " Ok(", |
| 966 | + " std::fs::read_to_string(file_name)?", |
| 967 | + " .lines()", |
| 968 | + " .map(String::from)", |
| 969 | + " .collect()", |
| 970 | + " )", |
| 971 | + "}", |
| 972 | + "", |
| 973 | + "// Usage:", |
| 974 | + "let lines = read_lines(\"path/to/file.txt\").expect(\"Failed to read lines from file\")" |
| 975 | + ], |
| 976 | + "tags": [ |
| 977 | + "rust", |
| 978 | + "file", |
| 979 | + "read", |
| 980 | + "utility" |
| 981 | + ], |
| 982 | + "author": "Mathys-Gasnier" |
| 983 | + }, |
| 984 | + { |
| 985 | + "title": "Find Files", |
| 986 | + "description": "Finds all files of the specified extension within a given directory.", |
| 987 | + "code": [ |
| 988 | + "fn find_files(directory: &str, file_type: &str) -> std::io::Result<Vec<std::path::PathBuf>> {", |
| 989 | + " let mut result = vec![];", |
| 990 | + "", |
| 991 | + " for entry in std::fs::read_dir(directory)? {", |
| 992 | + " let dir = entry?;", |
| 993 | + " let path = dir.path();", |
| 994 | + " if dir.file_type().is_ok_and(|t| !t.is_file()) &&", |
| 995 | + " path.extension().is_some_and(|ext| ext != file_type) {", |
| 996 | + " continue;", |
| 997 | + " }", |
| 998 | + " result.push(path)", |
| 999 | + " }", |
| 1000 | + "", |
| 1001 | + " Ok(result)", |
| 1002 | + "}", |
| 1003 | + "", |
| 1004 | + "// Usage:", |
| 1005 | + "let files = find_files(\"/path/to/your/directory\", \".pdf\")" |
| 1006 | + ], |
| 1007 | + "tags": [ |
| 1008 | + "rust", |
| 1009 | + "file", |
| 1010 | + "search" |
| 1011 | + ], |
| 1012 | + "author": "Mathys-Gasnier" |
| 1013 | + } |
| 1014 | + ] |
| 1015 | + }, |
927 | 1016 | {
|
928 | 1017 | "language": "scss",
|
929 | 1018 | "categoryName": "Typography",
|
|
0 commit comments