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

Adding some Rust snippets #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
technoph1le merged 2 commits into quicksnip-dev:main from Mathys-Gasnier:main
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Adding some rust snippets
  • Loading branch information
Mathys-Gasnier committed Dec 29, 2024
commit adbbf870b967afb99adc1f2f658b3e3d3dce3970
4 changes: 4 additions & 0 deletions public/data/_index.json
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@
{
"lang": "CPP",
"icon": "/icons/cpp.svg"
},
{
"lang": "Rust",
"icon": "/icons/rust.svg"
}
]
76 changes: 76 additions & 0 deletions public/data/rust.json
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[
{
"categoryName": "String Manipulation",
"snippets": [
{
"title": "Capitalize String",
"description": "Makes the first letter of a string uppercase.",
"code": [
"fn capitalized(str: &str) -> String {",
" let mut chars = str.chars();",
" match chars.next() {",
" None => String::new(),",
" Some(f) => f.to_uppercase().chain(chars).collect(),",
" }",
"}",
"",
"// Usage:",
"assert_eq!(capitalized(\"lower_case\"), \"Lower_case\")"
],
"tags": ["rust", "string", "capitalize", "utility"],
"author": "Mathys-Gasnier"
}
]
},
{
"categoryName": "File Handling",
"snippets": [
{
"title": "Read File Lines",
"description": "Reads all lines from a file and returns them as a vector of strings.",
"code": [
"fn read_lines(file_name: &str) -> std::io::Result<Vec<String>>",
" Ok(",
" std::fs::read_to_string(file_name)?",
" .lines()",
" .map(String::from)",
" .collect()",
" )",
"}",
"",
"// Usage:",
"let lines = read_lines(\"path/to/file.txt\").expect(\"Failed to read lines from file\")"
],
"tags": ["rust", "file", "read", "utility"],
"author": "Mathys-Gasnier"
},
{
"title": "Find Files",
"description": "Finds all files of the specified extension within a given directory.",
"code": [
"fn find_files(directory: &str, file_type: &str) -> std::io::Result<Vec<std::path::PathBuf>> {",
" let mut result = vec![];",
"",
" for entry in std::fs::read_dir(directory)? {",
" let dir = entry?;",
" let path = dir.path();",
" if dir.file_type().is_ok_and(|t| !t.is_file()) &&",
" path.extension().is_some_and(|ext| ext != file_type) {",
" continue;",
" }",
" result.push(path)",
" }",
"",
" Ok(result)",
"}",
"",
"// Usage:",
"let files = find_files(\"/path/to/your/directory\", \".pdf\")"
],
"tags": ["rust", "file", "search"],
"author": "Mathys-Gasnier"
}
]
}
]

7 changes: 7 additions & 0 deletions public/icons/rust.svg
View file Open in desktop
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
[フレーム]

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