{"id":19118904,"url":"https://github.com/yskszk63/lazylink","last_synced_at":"2026-06-12T23:32:56.970Z","repository":{"id":62441872,"uuid":"302935379","full_name":"yskszk63/lazylink","owner":"yskszk63","description":"Convert extern fn to libdl call procedural macro.","archived":false,"fork":false,"pushed_at":"2021-07-20T15:01:59.000Z","size":44,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-03T07:47:28.937Z","etag":null,"topics":["ffi","libdl","proc-macro","proc-macro-attributes"],"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/yskszk63.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-10T15:46:43.000Z","updated_at":"2021-07-20T15:02:02.000Z","dependencies_parsed_at":"2022-11-01T21:53:38.015Z","dependency_job_id":null,"html_url":"https://github.com/yskszk63/lazylink","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yskszk63%2Flazylink","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yskszk63%2Flazylink/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yskszk63%2Flazylink/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yskszk63%2Flazylink/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yskszk63","download_url":"https://codeload.github.com/yskszk63/lazylink/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240172167,"owners_count":19759506,"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":["ffi","libdl","proc-macro","proc-macro-attributes"],"created_at":"2024-11-09T05:08:02.613Z","updated_at":"2026-06-03T13:30:19.287Z","avatar_url":"https://github.com/yskszk63.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lazylink\n\n![build](https://github.com/yskszk63/lazylink/workflows/build/badge.svg)\n![check](https://github.com/yskszk63/lazylink/workflows/check/badge.svg)\n[![tokio-pipe](https://docs.rs/lazylink/badge.svg)](https://docs.rs/lazylink)\n\nConvert extern fn to libdl call procedural macro.\n\n```rust\nuse lazylink::lazylink;\n\n/// comment!\n#[lazylink]\n#[link(name = \"z\")]\nextern \"C\" {\n    /// zlib version\n    #[link_name = \"zlibVersion\"]\n    fn zlib_version() -\u003e *const std::os::raw::c_char;\n}\n\n#[lazylink(fullname = \"libc.so.6\")]\nmod libc {\n    /// comment!\n    extern \"C\" {\n        pub(crate) fn puts(v: *const std::os::raw::c_char);\n    }\n}\n\nfn main() {\n    let ver = unsafe {\n        zlib_version()\n    };\n    unsafe {\n        libc::puts(ver);\n    }\n}\n```\n\ninto\n\n```rust\n#![feature(prelude_import)]\n#[prelude_import]\nuse std::prelude::v1::*;\n#[macro_use]\nextern crate std;\nuse lazylink::lazylink;\nstruct __LazyLinkbfde0578a8e5d844\u003c'a\u003e {\n    /// comment!\n    /// zlib version\n    zlib_version:\n        lazylink::libloading::Symbol\u003c'a, unsafe extern \"C\" fn() -\u003e *const std::os::raw::c_char\u003e,\n    _phantom: std::marker::PhantomData\u003cfn() -\u003e \u0026'a ()\u003e,\n}\nimpl\u003c'a\u003e __LazyLinkbfde0578a8e5d844\u003c'a\u003e {\n    unsafe fn new(\n        lib: \u0026'a lazylink::libloading::Library,\n    ) -\u003e Result\u003cSelf, lazylink::libloading::Error\u003e {\n        Ok(\n            Self { # [doc = \" comment!\"] # [doc = \" zlib version\"] zlib_version : lib . get (b\"zlibVersion\\x00\") ? , _pha\nntom : std :: marker :: PhantomData , },\n        )\n    }\n    fn get() -\u003e \u0026'static __LazyLinkbfde0578a8e5d844\u003c'static\u003e {\n        static mut LIB: Option\u003clazylink::libloading::Library\u003e = None;\n        static mut FNS: Option\u003c__LazyLinkbfde0578a8e5d844\u003c'static\u003e\u003e = None;\n        static ONCE: std::sync::Once = std::sync::Once::new();\n        ONCE.call_once(|| unsafe {\n            LIB = Some(\n                lazylink::libloading::Library::new(lazylink::libloading::library_filename(\"z\"))\n                    .unwrap(),\n            );\n            FNS = Some(__LazyLinkbfde0578a8e5d844::new(LIB.as_ref().unwrap()).unwrap());\n        });\n        unsafe { FNS.as_ref().unwrap() }\n    }\n}\n/// comment!\n/// zlib version\nunsafe fn zlib_version() -\u003e *const std::os::raw::c_char {\n    (__LazyLinkbfde0578a8e5d844::get().zlib_version)()\n}\nmod libc {\n    struct __LazyLink79e825dc6d38824d\u003c'a\u003e {\n        /// comment!\n        puts: lazylink::libloading::Symbol\u003c'a, unsafe extern \"C\" fn(*const std::os::raw::c_char)\u003e,\n        _phantom: std::marker::PhantomData\u003cfn() -\u003e \u0026'a ()\u003e,\n    }\n    impl\u003c'a\u003e __LazyLink79e825dc6d38824d\u003c'a\u003e {\n        unsafe fn new(\n            lib: \u0026'a lazylink::libloading::Library,\n        ) -\u003e Result\u003cSelf, lazylink::libloading::Error\u003e {\n            Ok(\n                Self { # [doc = \" comment!\"] puts : lib . get (b\"puts\\x00\") ? , _phantom : std :: marker :: PhantomData ,\n },\n            )\n        }\n        fn get() -\u003e \u0026'static __LazyLink79e825dc6d38824d\u003c'static\u003e {\n            static mut LIB: Option\u003clazylink::libloading::Library\u003e = None;\n            static mut FNS: Option\u003c__LazyLink79e825dc6d38824d\u003c'static\u003e\u003e = None;\n            const ONCE: std::sync::Once = std::sync::Once::new();\n            ONCE.call_once(|| unsafe {\n                LIB = Some(lazylink::libloading::Library::new(\"libc.so.6\").unwrap());\n                FNS = Some(__LazyLink79e825dc6d38824d::new(LIB.as_ref().unwrap()).unwrap());\n            });\n            unsafe { FNS.as_ref().unwrap() }\n        }\n    }\n    /// comment!\n    pub(crate) unsafe fn puts(v: *const std::os::raw::c_char) {\n        (__LazyLink79e825dc6d38824d::get().puts)(v)\n    }\n}\nfn main() {\n    let ver = unsafe { zlib_version() };\n    unsafe {\n        libc::puts(ver);\n    }\n}\n```\n\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0\n   ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license\n   ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n## Contribution\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 be\ndual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyskszk63%2Flazylink","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyskszk63%2Flazylink","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyskszk63%2Flazylink/lists"}