{"id":18542849,"url":"https://github.com/bincode-org/virtue","last_synced_at":"2025-05-15T22:11:50.314Z","repository":{"id":38800442,"uuid":"434854812","full_name":"bincode-org/virtue","owner":"bincode-org","description":"A sinless derive helper","archived":false,"fork":false,"pushed_at":"2024-11-08T14:20:29.000Z","size":161,"stargazers_count":72,"open_issues_count":5,"forks_count":10,"subscribers_count":7,"default_branch":"trunk","last_synced_at":"2025-05-08T00:13:46.041Z","etag":null,"topics":[],"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/bincode-org.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-04T09:09:01.000Z","updated_at":"2025-04-03T08:45:51.000Z","dependencies_parsed_at":"2023-01-20T21:17:46.888Z","dependency_job_id":"33021e49-89d5-410b-b9ca-32533f7a1ac0","html_url":"https://github.com/bincode-org/virtue","commit_stats":{"total_commits":57,"total_committers":6,"mean_commits":9.5,"dds":0.4385964912280702,"last_synced_commit":"789c14a7aff1a5990c86accbc541fb9d146125d1"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bincode-org%2Fvirtue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bincode-org%2Fvirtue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bincode-org%2Fvirtue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bincode-org%2Fvirtue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bincode-org","download_url":"https://codeload.github.com/bincode-org/virtue/tar.gz/refs/heads/trunk","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254430331,"owners_count":22069909,"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":[],"created_at":"2024-11-06T20:10:55.379Z","updated_at":"2025-05-15T22:11:50.245Z","avatar_url":"https://github.com/bincode-org.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Virtue, a sinless derive macro helper\n\n## Goals\n\n- Zero dependencies, so fast compile times\n- No other dependencies needed\n- Declarative code generation\n- As much typesystem checking as possible\n- Build for modern rust: 1.57 and up\n- Build with popular crates in mind:\n  - [bincode](https://docs.rs/bincode)\n- Will always respect semver. Minor releases will never have:\n  - Breaking API changes\n  - MSRV changes\n\n## Example\n\n```rust\nuse virtue::prelude::*;\n\n#[proc_macro_derive(YourDerive, attributes(some, attributes, go, here))]\npub fn derive_your_derive(input: TokenStream) -\u003e TokenStream {\n    derive_your_derive_inner(input)\n        .unwrap_or_else(|error| error.into_token_stream())\n}\n\nfn derive_your_derive_inner(input: TokenStream) -\u003e Result\u003cTokenStream\u003e {\n    // Parse the struct or enum you want to implement a derive for\n    let parse = Parse::new(input)?;\n    // Get a reference to the generator\n    let (mut generator, body) = parse.into_generator();\n    match body {\n        Body::Struct(body) =\u003e {\n            // Implement your struct body here\n            // See `Generator` for more information\n            generator.impl_for(\"YourTrait\")?\n                    .generate_fn(\"your_fn\")\n                    .with_self_arg(FnSelfArg::RefSelf)\n                    .body(|fn_body| {\n                        fn_body.push_parsed(\"println!(\\\"Hello world\\\");\");\n                    })?;\n        },\n        Body::Enum(body) =\u003e {\n            // Implement your enum body here\n            // See `Generator` for more information\n            generator.impl_for(\"YourTrait\")?\n                    .generate_fn(\"your_fn\")\n                    .with_self_arg(FnSelfArg::RefSelf)\n                    .body(|fn_body| {\n                        fn_body.push_parsed(\"println!(\\\"Hello world\\\");\");\n                    })?;\n        },\n    }\n    generator.finish()\n}\n```\n\nWill generate\n\n```ignore\nimpl YourTrait for \u003cStruct or Enum\u003e {\n    fn your_fn(\u0026self) { // .generate_fn(\"your_fn\").with_self_arg(FnSelfArg::RefSelf)\n        println!(\"Hello world\"); // fn_body.push_parsed(...)\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbincode-org%2Fvirtue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbincode-org%2Fvirtue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbincode-org%2Fvirtue/lists"}