-
-
Notifications
You must be signed in to change notification settings - Fork 128
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
+86
−0
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
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
commit adbbf870b967afb99adc1f2f658b3e3d3dce3970
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,9 @@ | |
{ | ||
"lang": "CPP", | ||
"icon": "/icons/cpp.svg" | ||
}, | ||
{ | ||
"lang": "Rust", | ||
"icon": "/icons/rust.svg" | ||
} | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} | ||
] | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.