{"id":17158076,"url":"https://github.com/vrmiguel/negate","last_synced_at":"2025-10-11T16:37:04.340Z","repository":{"id":57644099,"uuid":"402901578","full_name":"vrmiguel/negate","owner":"vrmiguel","description":"Attribute macro that generates negated versions of`is_something` functions","archived":false,"fork":false,"pushed_at":"2021-09-04T23:26:01.000Z","size":30,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T04:33:23.048Z","etag":null,"topics":["macro","proc-macro","proc-macro-attributes","rust","rust-lang"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/negate","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/vrmiguel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-03T21:28:18.000Z","updated_at":"2022-03-04T02:48:54.000Z","dependencies_parsed_at":"2022-08-30T05:12:58.769Z","dependency_job_id":null,"html_url":"https://github.com/vrmiguel/negate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrmiguel%2Fnegate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrmiguel%2Fnegate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrmiguel%2Fnegate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrmiguel%2Fnegate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vrmiguel","download_url":"https://codeload.github.com/vrmiguel/negate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248720945,"owners_count":21151015,"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":["macro","proc-macro","proc-macro-attributes","rust","rust-lang"],"created_at":"2024-10-14T22:10:30.464Z","updated_at":"2025-10-03T17:56:43.512Z","avatar_url":"https://github.com/vrmiguel.png","language":"Rust","readme":"# negate\n\nnegate is a simple attribute macro that negates a given function.\n\n\n## Usage\n\n### `#[negate]`\n\nGiven a function of the form `is_*` that returns a boolean value, the macro will create a `is_not_*` function that negates the given function.\n\n\n```rust\nstruct Word(\u0026'static str);\n\nimpl Word {\n    pub fn new(word: \u0026'static str) -\u003e Self {\n        Self (word)\n    }\n\n    #[negate] // \u003c- negate will implement a `is_not_uppercase` function!\n    pub fn is_uppercase(\u0026self) -\u003e bool {\n        self.0 == self.0.to_uppercase()\n    }\n}\nlet my_name = Word::new(\"My Name\");\n\nassert!(my_name.is_not_uppercase());\n```\n    \n\n### `#[negate(name = \"...\")]`\n\nUsing the name attribute allows you to set the name of the generated function. This also allows the usage of the [negate] macro with functions that do not start with `is_`.\n\n```rust\nuse negate::negate;\n\npub enum TaskState {\n    Ready,\n    Finished,\n}\n\npub struct Reactor {\n    tasks: HashMap\u003cusize, TaskState\u003e,\n}\n\nimpl Reactor {\n    // Generates the `is_finished` function\n    #[negate(name = \"is_finished\")]\n    pub fn is_ready(\u0026self, id: usize) -\u003e bool {\n        self.tasks.get(\u0026id).map(|state| match state {\n            TaskState::Ready =\u003e true,\n            _ =\u003e false,\n        }).unwrap_or(false)\n    }\n}\n```\n\n### `#[negate(docs = \"...\")]`\n\nUsing the docs attribute allows you to customize the doc-string of the generated function.\n\n```rust\nuse negate::negate;\n#[negate(name = \"is_odd\", docs = \"returns true if the given number is odd\")]\nfn is_even(x: i32) -\u003e bool {\n   x % 2 == 0\n}\nassert!(is_odd(5));\n```\n\n\n## How does the generated code look like?\n\n### Non-associated functions\n\n```rust\n#[negate]\npub fn is_even(x: i32) -\u003e bool {\n    x % 2 == 0\n}\n```\n\nWill expand to:\n\n```rust\npub fn is_even(x: i32) -\u003e bool {\n    x % 2 == 0\n}\n\n/// This is an automatically generated function that denies [`is_even`].\n/// Consult the original function for more information.\npub fn is_not_even(x: i32) -\u003e bool {\n    !is_even(x)\n}\n```\n\nUsing generics is likewise not a problem\n\n```rust\n#[negate]\nfn is_equal\u003cT\u003e(x: T, y: T) -\u003e bool\nwhere\n    T: Eq,\n{\n    x == y\n}\n```\n\nThe generated negated function:\n\n```rust\n/// This is an automatically generated function that denies [`is_equal`].\n/// Consult the original function for more information.\nfn is_not_equal\u003cT\u003e(x: T, y: T) -\u003e bool\nwhere\n    T: Eq,\n{\n    !is_equal(x, y)\n}\n```\n\n### Associated functions\n\n```rust\nstruct BigInt {\n    ..\n};\n\nimpl BigInt {\n    #[negate(name = \"is_negative\", docs = \"Returns true if the number is negative and false if the number is zero or positive.\")]\n    pub fn is_positive(\u0026self) -\u003e bool { .. }\n}\n```\n\nBecomes:\n\n```rust\nimpl BigInt {\n    pub fn is_positive(\u0026self) -\u003e bool { .. }\n    \n    /// Returns true if the number is negative and false if the number is zero or positive.\n    pub fn is_negative(\u0026self) -\u003e bool {\n        !self.is_positive()\n    }\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvrmiguel%2Fnegate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvrmiguel%2Fnegate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvrmiguel%2Fnegate/lists"}