{"id":20660833,"url":"https://github.com/lxl66566/once-fn","last_synced_at":"2025-04-19T15:11:15.135Z","repository":{"id":257815146,"uuid":"869077623","full_name":"lxl66566/once-fn","owner":"lxl66566","description":"Call function only once, cache the first result","archived":false,"fork":false,"pushed_at":"2025-04-01T09:21:26.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-13T01:18:36.105Z","etag":null,"topics":["macros","proc-macro-attributes","rust"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/once-fn","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/lxl66566.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-07T17:19:08.000Z","updated_at":"2025-04-01T09:21:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"14c9a56b-2a91-4814-8afc-854cdc76d9f9","html_url":"https://github.com/lxl66566/once-fn","commit_stats":null,"previous_names":["lxl66566/once-fn"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxl66566%2Fonce-fn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxl66566%2Fonce-fn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxl66566%2Fonce-fn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxl66566%2Fonce-fn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lxl66566","download_url":"https://codeload.github.com/lxl66566/once-fn/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249723284,"owners_count":21315992,"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":["macros","proc-macro-attributes","rust"],"created_at":"2024-11-16T19:06:13.382Z","updated_at":"2025-04-19T15:11:15.105Z","avatar_url":"https://github.com/lxl66566.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# once-fn\n\nThis crate focuses on one simple thing: **make a function runs only once**. All subsequent calls will return the result of the first call.\n\n## Limitations\n\n- Return type must satisfy:\n  - Implements `Clone`, or a reference points to a type that implements `Clone`.\n  - could not be generics type or `impl` clause.\n\n## Example\n\n```rust\nuse once_fn::once;\n\n#[once]\npub fn foo(b: bool) -\u003e bool {\n    b\n}\nassert!(foo(true));  // set the return value to `true`\nassert!(foo(false)); // will not run this function twice; directly return `true`.\n\n// allows ref:\n#[once]\npub fn foo2(b: \u0026bool) -\u003e \u0026bool {\n    b\n}\n```\n\nfor impl block:\n\n```rust\nuse once_fn::once_impl;\nstruct Foo;\n\n#[once_impl]\nimpl Foo {\n    #[once]\n    pub fn foo(b: bool) -\u003e bool {\n        b\n    }\n}\n```\n\nsee [tests](./tests/) for more examples.\n\n## Why not\n\n- `cached::proc_macro::once`\n  - does not support async fn\n  - does not support generics (in input)\n  - does not support reference (in return type)\n  - does not support use in impl block\n- `fn-once`\n  - Almost no docs; I don't know what it actually do.\n  - It can't even compile its example\n\n## MSRV\n\n1.61.0 (nightly), 1.70.0 (stable)\n\n## todo\n\n- [x] support impl block\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flxl66566%2Fonce-fn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flxl66566%2Fonce-fn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flxl66566%2Fonce-fn/lists"}