{"id":13822560,"url":"https://github.com/taiki-e/const_fn","last_synced_at":"2025-04-05T05:04:42.245Z","repository":{"id":45180751,"uuid":"163108241","full_name":"taiki-e/const_fn","owner":"taiki-e","description":"A lightweight attribute for easy generation of const functions with conditional compilations.","archived":false,"fork":false,"pushed_at":"2025-03-20T17:56:55.000Z","size":392,"stargazers_count":27,"open_issues_count":3,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-31T17:08:24.284Z","etag":null,"topics":["no-std","proc-macro","rust"],"latest_commit_sha":null,"homepage":"https://docs.rs/const_fn","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/taiki-e.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","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},"funding":{"github":"taiki-e"}},"created_at":"2018-12-25T19:58:23.000Z","updated_at":"2025-03-20T17:56:59.000Z","dependencies_parsed_at":"2023-12-24T11:30:55.157Z","dependency_job_id":"adc881d3-8ece-479b-b19d-be869b3501d7","html_url":"https://github.com/taiki-e/const_fn","commit_stats":{"total_commits":402,"total_committers":1,"mean_commits":402.0,"dds":0.0,"last_synced_commit":"ddc9ea9d60189f21b7f677862cc97d30e9f8ff19"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taiki-e%2Fconst_fn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taiki-e%2Fconst_fn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taiki-e%2Fconst_fn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taiki-e%2Fconst_fn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/taiki-e","download_url":"https://codeload.github.com/taiki-e/const_fn/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247289424,"owners_count":20914464,"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":["no-std","proc-macro","rust"],"created_at":"2024-08-04T08:02:06.264Z","updated_at":"2025-04-05T05:04:42.226Z","avatar_url":"https://github.com/taiki-e.png","language":"Rust","readme":"# \\#\\[const_fn\\]\n\n[![crates.io](https://img.shields.io/crates/v/const_fn?style=flat-square\u0026logo=rust)](https://crates.io/crates/const_fn)\n[![docs.rs](https://img.shields.io/badge/docs.rs-const__fn-blue?style=flat-square\u0026logo=docs.rs)](https://docs.rs/const_fn)\n[![license](https://img.shields.io/badge/license-Apache--2.0_OR_MIT-blue?style=flat-square)](#license)\n[![msrv](https://img.shields.io/badge/msrv-1.31-blue?style=flat-square\u0026logo=rust)](https://www.rust-lang.org)\n[![github actions](https://img.shields.io/github/actions/workflow/status/taiki-e/const_fn/ci.yml?branch=main\u0026style=flat-square\u0026logo=github)](https://github.com/taiki-e/const_fn/actions)\n\nA lightweight attribute for easy generation of const functions with conditional\ncompilations.\n\n## Usage\n\nAdd this to your `Cargo.toml`:\n\n```toml\n[dependencies]\nconst_fn = \"0.4\"\n```\n\n## Examples\n\n```rust\nuse const_fn::const_fn;\n\n// function is `const` on specified version and later compiler (including beta, nightly, and dev build)\n#[const_fn(\"1.36\")]\npub const fn version() {\n    /* ... */\n}\n\n// function is `const` on nightly compiler (including dev build)\n#[const_fn(nightly)]\npub const fn nightly() {\n    /* ... */\n}\n\n// function is `const` if `cfg(...)` is true\n#[const_fn(cfg(...))]\npub const fn cfg() {\n    /* ... */\n}\n\n// function is `const` if `cfg(feature = \"...\")` is true\n#[const_fn(feature = \"...\")]\npub const fn feature() {\n    /* ... */\n}\n```\n\n### Use this crate as an optional dependency\n\nIf no arguments are passed, `const_fn` will always make the function `const`.\n\nTherefore, you can use `const_fn` as an optional dependency by combination with `cfg_attr`.\n\n```rust\n// function is `const` if `cfg(feature = \"...\")` is true\n#[cfg_attr(feature = \"...\", const_fn::const_fn)]\npub fn optional() {\n    /* ... */\n}\n```\n\n\u003c!--\nTODO: document the behavior on the version on the nightly channel.\n      https://github.com/taiki-e/const_fn/issues/27\n      https://github.com/rust-lang/rust/pull/81468\n--\u003e\n\n## Alternatives\n\nThis crate is proc-macro, but is very lightweight, and has no dependencies.\n\nYou can manually define declarative macros with similar functionality (see\n[`if_rust_version`](https://github.com/ogoffart/if_rust_version#examples)),\nor [you can define the same function twice with different cfg](https://github.com/crossbeam-rs/crossbeam/blob/0b6ea5f69fde8768c1cfac0d3601e0b4325d7997/crossbeam-epoch/src/atomic.rs#L340-L372).\n(Note: the former approach requires more macros to be defined depending on the\nnumber of version requirements, the latter approach requires more functions to\nbe maintained manually)\n\n## License\n\nLicensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or\n[MIT license](LICENSE-MIT) at your option.\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall\nbe dual licensed as above, without any additional terms or conditions.\n","funding_links":["https://github.com/sponsors/taiki-e"],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaiki-e%2Fconst_fn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftaiki-e%2Fconst_fn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaiki-e%2Fconst_fn/lists"}