{"id":21500263,"url":"https://github.com/clucompany/clustaticdata","last_synced_at":"2025-03-17T13:15:44.107Z","repository":{"id":57606573,"uuid":"184571830","full_name":"clucompany/cluStaticData","owner":"clucompany","description":"[deprecated] Initializers of static values. Manual initialization (using safe functions and zero cost when accessing an object) or automatic initialization during accessing an object (there is no zero cost when accessing an object; you must set the correct default value).","archived":false,"fork":false,"pushed_at":"2019-08-23T17:16:10.000Z","size":57,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-23T22:41:36.560Z","etag":null,"topics":["clucompany","clustaticdata","library","rust-library","static-data"],"latest_commit_sha":null,"homepage":"","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/clucompany.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":"2019-05-02T11:49:50.000Z","updated_at":"2024-05-12T22:53:08.000Z","dependencies_parsed_at":"2022-09-21T01:42:14.910Z","dependency_job_id":null,"html_url":"https://github.com/clucompany/cluStaticData","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clucompany%2FcluStaticData","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clucompany%2FcluStaticData/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clucompany%2FcluStaticData/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clucompany%2FcluStaticData/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clucompany","download_url":"https://codeload.github.com/clucompany/cluStaticData/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244039241,"owners_count":20387835,"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":["clucompany","clustaticdata","library","rust-library","static-data"],"created_at":"2024-11-23T17:23:09.414Z","updated_at":"2025-03-17T13:15:44.079Z","avatar_url":"https://github.com/clucompany.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cluStaticData\n[![Build Status](https://travis-ci.org/clucompany/cluStaticData.svg?branch=master)](https://travis-ci.org/clucompany/cluStaticData)\n[![Apache licensed](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](./LICENSE)\n[![crates.io](http://meritbadge.herokuapp.com/cluStaticData)](https://crates.io/crates/cluStaticData)\n[![Documentation](https://docs.rs/cluStaticData/badge.svg)](https://docs.rs/cluStaticData)\n\nInitializers of static values. Manual initialization (using safe functions and zero cost when accessing an object) or automatic initialization during accessing an object (there is no zero cost when accessing an object; you must set the correct default value).\n\n1. Manual initialization of static data.\n2. Automatic initialization of static data.\n\n\n# Use (Manual initialization of static data)\n\n```rust\n#[macro_use]\nextern crate cluStaticData;\n\nuse std::fmt::Debug;\nuse cluStaticData::err::StaticErr;\n\n\nstatic_data! {\n\tstatic ref TEST: \u0026'static (dyn MyTrait + 'static) = \u0026();\n}\n\npub trait MyTrait: Debug + Sync {\n\tfn data(\u0026self) -\u003e usize;\n}\n\nimpl MyTrait for () {\n\t#[inline]\n\tfn data(\u0026self) -\u003e usize {\n\t\t0\n\t}\n}\n\nimpl MyTrait for usize {\n\t#[inline]\n\tfn data(\u0026self) -\u003e usize {\n\t\t*self\n\t}\n}\n\nfn main() -\u003e Result\u003c(), StaticErr\u003c\u0026'static (dyn MyTrait + 'static)\u003e\u003e {\n\tlet _result = TEST.set(\u002610)?;\n\tprintln!(\"OK {:?}, data: {:?}\", TEST, TEST.data());\n\t\n\tlet err = TEST.set(\u002620);\n\tassert_eq!(err.err().unwrap().into_inner().data(), 20);\n\tprintln!(\"OK {:?}, data: {:?}\", TEST, TEST.data());\n\t\n\tOk( () )\n}\n```\n\n# Use 2 (Manual initialization of static data)\n\n```rust\n#[macro_use]\nextern crate cluStaticData;\nuse cluStaticData::err::StaticErr;\n\nstatic_data! {\n\tpub(crate) static ref TEST: TestValue = TestValue::Unk;\n}\n\n#[derive(Debug, Clone, Copy, PartialEq)]\npub enum TestValue {\n\tUnk,\n\tRuntimeValue(usize),\n}\n\nfn main() {\n\tassert_eq!(*TEST, TestValue::Unk);\n\tprintln!(\"OK #1 {:?}\", TEST);\n\t\n\tlet result = TEST.set(TestValue::RuntimeValue(10));\n\tassert_eq!(result.is_ok(), true);\n\tprintln!(\"OK #2 {:?}\", TEST);\n\t\n\tlet result = TEST.set(TestValue::RuntimeValue(20));\n\tassert_eq!(result.is_ok(), false);\n\tassert_eq!(*TEST, TestValue::RuntimeValue(10));\n\tprintln!(\"OK #3 {:?}\", TEST);\n\t\n\tlet result = TEST.replace(TestValue::Unk);\n\tassert_eq!(result, Err(StaticErr::prev(TestValue::Unk)));\n\tprintln!(\"OK #4 {:?}\", result);\n}\n```\n\n# Use 3 (Automatic initialization of static data)\n\n```rust\n#[macro_use]\nextern crate cluStaticData;\n\nuse std::collections::HashMap;\n\nstatic_data! {\n\tpub(crate) static ref +runtime HASH_MAP: HashMap\u003cString, String\u003e = {\n\t\tlet mut hash_map = HashMap::new();\n\t\thash_map.insert(\"test\".to_string(), \"b\".to_string());\n\t\thash_map.insert(\"test2\".to_string(), \"b2\".to_string());\n\n\t\thash_map\n\t};\n\tstatic ref +runtime HASH_MAP2: usize = 0;\n}\n\nfn main() {\n\tprintln!(\"{:?}\", HASH_MAP);\n}\n```\n\n# License\n\nCopyright 2019 #UlinProject Denis Kotlyarov (Денис Котляров)\n\nLicensed under the Apache License, Version 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclucompany%2Fclustaticdata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclucompany%2Fclustaticdata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclucompany%2Fclustaticdata/lists"}