{"id":13484824,"url":"https://github.com/hatoo/cargo-snippet","last_synced_at":"2025-08-20T03:30:41.978Z","repository":{"id":57538681,"uuid":"116558609","full_name":"hatoo/cargo-snippet","owner":"hatoo","description":"A snippet extrator for competitive programmers","archived":false,"fork":false,"pushed_at":"2020-08-08T07:05:37.000Z","size":190,"stargazers_count":75,"open_issues_count":4,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-09T21:34:04.846Z","etag":null,"topics":["cargo","competitive-programming","rust","snippet-manager","snippets-manager"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hatoo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-07T11:08:08.000Z","updated_at":"2024-09-15T07:49:31.000Z","dependencies_parsed_at":"2022-09-19T07:31:47.815Z","dependency_job_id":null,"html_url":"https://github.com/hatoo/cargo-snippet","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hatoo%2Fcargo-snippet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hatoo%2Fcargo-snippet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hatoo%2Fcargo-snippet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hatoo%2Fcargo-snippet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hatoo","download_url":"https://codeload.github.com/hatoo/cargo-snippet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230050962,"owners_count":18165154,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cargo","competitive-programming","rust","snippet-manager","snippets-manager"],"created_at":"2024-07-31T17:01:35.008Z","updated_at":"2024-12-19T06:08:58.423Z","avatar_url":"https://github.com/hatoo.png","language":"Rust","funding_links":[],"categories":["Rust","rust"],"sub_categories":[],"readme":"# cargo-snippet\n\n[![crates.io](https://img.shields.io/crates/v/cargo-snippet.svg)](https://crates.io/crates/cargo-snippet)\n[![Build Status](https://travis-ci.org/hatoo/cargo-snippet.svg?branch=master)](https://travis-ci.org/hatoo/cargo-snippet)\n[![dependency status](https://deps.rs/repo/github/hatoo/cargo-snippet/status.svg)](https://deps.rs/repo/github/hatoo/cargo-snippet)\n\nA snippet extractor for competitive programmers.\n\nThis allows you to manage your code snippets with tests and benchmarks available !!\n\n## Installing\n\nYou need to install `rustfmt` to run `cargo-snippet`.\n\n```bash\n$ rustup component add rustfmt\n```\n\nInstall `cargo-snippet`\n\n```bash\n$ cargo install cargo-snippet --features=\"binaries\"\n```\n\n## Usage\n\nCreate a project for snippet.\n\n```\n$ cargo new --lib mysnippet\n```\n\nAdd dependencies to Cargo.toml.\n\n```toml\n[dependencies]\ncargo-snippet = \"0.6\"\n```\n\nNote: `cargo-snippet` on dependencies is needed just for register `#[snippet]` attribute to prevent the error from the compiler.\nAll logics that extract snippet is in the binary package which is installed by `Installing` section.\n\nThen write some snippet codes and tests.\n\n```rust\nuse cargo_snippet::snippet;\n\n// Annotate snippet name\n#[snippet(\"mymath\")]\n#[snippet(\"gcd\")]\nfn gcd(a: u64, b: u64) -\u003e u64 {\n    if b == 0 {\n        a\n    } else {\n        gcd(b, a % b)\n    }\n}\n\n// Also works\n#[snippet(name = \"mymath\")]\n// Equivalent to #[snippet(\"lcm\")]\n#[snippet]\nfn lcm(a: u64, b: u64) -\u003e u64 {\n    a / gcd(a, b) * b\n}\n\n#[snippet]\n// Include snippet\n#[snippet(include = \"gcd\")]\nfn gcd_list(list: \u0026[u64]) -\u003e u64 {\n    list.iter().fold(list[0], |a, \u0026b| gcd(a, b))\n}\n\n// You can set prefix string.\n// Note: All codes will be formatted by rustfmt on output\n#[snippet(prefix = \"use std::io::{self,Read};\")]\n#[snippet(prefix = \"use std::str::FromStr;\")]\nfn foo() {}\n\n// By default, doc comments associated with items will be output with the snippet.\n#[snippet]\n/// This is a document!\nfn documented() {\n    //! Inner document also works.\n}\n\n// If you want doc comment to be hidden, append `doc_hidden` keyword.\n#[snippet(doc_hidden, prefix = \"use std::collections::HashMap;\")]\n/// This is a doc comment for `bar`.\n/// Since `doc_hidden` is specified, it won't be present in the snippet.\nfn bar() {\n    //! And this is also a doc comment for `bar`, which will be removed.\n}\n\n#[test]\nfn test_gcd() {\n    assert_eq!(gcd(57, 3), 3);\n}\n\n#[test]\nfn test_lcm() {\n    assert_eq!(lcm(3, 19), 57);\n}\n```\n\nYou can test as always:\n\n```\n$ cargo test\n```\n\nExtract snippet !\n\n```\n$ cargo snippet\nsnippet foo\n    use std::io::{self, Read};\n    use std::str::FromStr;\n    fn foo() {}\n\nsnippet documented\n    /// This is a document!\n    fn documented() {\n        //! Inner document also works.\n    }\n\nsnippet bar\n    use std::collections::HashMap;\n    fn bar() {}\n\nsnippet gcd\n    fn gcd(a: u64, b: u64) -\u003e u64 {\n        if b == 0 {\n            a\n        } else {\n            gcd(b, a % b)\n        }\n    }\n\nsnippet gcd_list\n    fn gcd(a: u64, b: u64) -\u003e u64 {\n        if b == 0 {\n            a\n        } else {\n            gcd(b, a % b)\n        }\n    }\n    fn gcd_list(list: \u0026[u64]) -\u003e u64 {\n        list.iter().fold(list[0], |a, \u0026b| gcd(a, b))\n    }\n\nsnippet lcm\n    fn lcm(a: u64, b: u64) -\u003e u64 {\n        a / gcd(a, b) * b\n    }\n\nsnippet mymath\n    fn gcd(a: u64, b: u64) -\u003e u64 {\n        if b == 0 {\n            a\n        } else {\n            gcd(b, a % b)\n        }\n    }\n    fn lcm(a: u64, b: u64) -\u003e u64 {\n        a / gcd(a, b) * b\n    }\n\n```\n\n## Example\n\nMy snippets [here](https://github.com/hatoo/competitive-rust-snippets.git).\n\n## Supported output format\n\n* Neosnippet\n* VScode\n* Ultisnips\n\nYou can specify output format via `-t` option.\nSee `cargo snippet -h`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhatoo%2Fcargo-snippet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhatoo%2Fcargo-snippet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhatoo%2Fcargo-snippet/lists"}