Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f55831f

Browse files
Merge pull request #13 from Mathys-Gasnier/main
Adding some Rust snippets
2 parents 286578b + 511e059 commit f55831f

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

‎public/data/_index.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@
1818
{
1919
"lang": "CPP",
2020
"icon": "/icons/cpp.svg"
21+
},
22+
{
23+
"lang": "Rust",
24+
"icon": "/icons/rust.svg"
2125
}
2226
]

‎public/data/rust.json‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
]

‎public/icons/rust.svg‎

Lines changed: 7 additions & 0 deletions
Loading[フレーム]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /