{"id":15994679,"url":"https://github.com/taiki-e/easy-ext","last_synced_at":"2025-04-04T21:09:48.687Z","repository":{"id":34218311,"uuid":"171730215","full_name":"taiki-e/easy-ext","owner":"taiki-e","description":"A lightweight attribute macro for easily writing extension trait pattern.","archived":false,"fork":false,"pushed_at":"2024-10-20T18:54:23.000Z","size":422,"stargazers_count":45,"open_issues_count":2,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-10-20T23:28:17.871Z","etag":null,"topics":["no-std","proc-macro","rust"],"latest_commit_sha":null,"homepage":"https://docs.rs/easy-ext","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":"2019-02-20T18:49:55.000Z","updated_at":"2024-10-20T18:54:27.000Z","dependencies_parsed_at":"2023-02-15T10:31:02.330Z","dependency_job_id":"bed391cc-e7a4-42f7-ae95-0d4f4edc4e50","html_url":"https://github.com/taiki-e/easy-ext","commit_stats":{"total_commits":357,"total_committers":1,"mean_commits":357.0,"dds":0.0,"last_synced_commit":"4c4f0a3127d65c02b1edd72295829131712d46bf"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taiki-e%2Feasy-ext","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taiki-e%2Feasy-ext/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taiki-e%2Feasy-ext/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taiki-e%2Feasy-ext/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/taiki-e","download_url":"https://codeload.github.com/taiki-e/easy-ext/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247249532,"owners_count":20908212,"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-10-08T07:09:46.351Z","updated_at":"2025-04-04T21:09:48.671Z","avatar_url":"https://github.com/taiki-e.png","language":"Rust","readme":"# easy-ext\n\n[![crates.io](https://img.shields.io/crates/v/easy-ext?style=flat-square\u0026logo=rust)](https://crates.io/crates/easy-ext)\n[![docs.rs](https://img.shields.io/badge/docs.rs-easy--ext-blue?style=flat-square\u0026logo=docs.rs)](https://docs.rs/easy-ext)\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/easy-ext/ci.yml?branch=main\u0026style=flat-square\u0026logo=github)](https://github.com/taiki-e/easy-ext/actions)\n\n\u003c!-- tidy:sync-markdown-to-rustdoc:start:src/lib.rs --\u003e\n\nA lightweight attribute macro for easily writing [extension trait pattern][rfc0445].\n\n```toml\n[dependencies]\neasy-ext = \"1\"\n```\n\n## Examples\n\n```rust\nuse easy_ext::ext;\n\n#[ext(ResultExt)]\npub impl\u003cT, E\u003e Result\u003cT, E\u003e {\n    fn err_into\u003cU\u003e(self) -\u003e Result\u003cT, U\u003e\n    where\n        E: Into\u003cU\u003e,\n    {\n        self.map_err(Into::into)\n    }\n}\n```\n\nCode like this will be generated:\n\n```rust\npub trait ResultExt\u003cT, E\u003e {\n    fn err_into\u003cU\u003e(self) -\u003e Result\u003cT, U\u003e\n    where\n        E: Into\u003cU\u003e;\n}\n\nimpl\u003cT, E\u003e ResultExt\u003cT, E\u003e for Result\u003cT, E\u003e {\n    fn err_into\u003cU\u003e(self) -\u003e Result\u003cT, U\u003e\n    where\n        E: Into\u003cU\u003e,\n    {\n        self.map_err(Into::into)\n    }\n}\n```\n\nYou can elide the trait name.\n\n```rust\nuse easy_ext::ext;\n\n#[ext]\nimpl\u003cT, E\u003e Result\u003cT, E\u003e {\n    fn err_into\u003cU\u003e(self) -\u003e Result\u003cT, U\u003e\n    where\n        E: Into\u003cU\u003e,\n    {\n        self.map_err(Into::into)\n    }\n}\n```\n\nNote that in this case, `#[ext]` assigns a random name, so you cannot\nimport/export the generated trait.\n\n### Visibility\n\nThere are two ways to specify visibility.\n\n#### Impl-level visibility\n\nThe first way is to specify visibility at the impl level. For example:\n\n```rust\nuse easy_ext::ext;\n\n// unnamed\n#[ext]\npub impl str {\n    fn foo(\u0026self) {}\n}\n\n// named\n#[ext(StrExt)]\npub impl str {\n    fn bar(\u0026self) {}\n}\n```\n\n#### Associated-item-level visibility\n\nAnother way is to specify visibility at the associated item level.\n\nFor example, if the method is `pub` then the trait will also be `pub`:\n\n```rust\nuse easy_ext::ext;\n\n#[ext(ResultExt)] // generate `pub trait ResultExt`\nimpl\u003cT, E\u003e Result\u003cT, E\u003e {\n    pub fn err_into\u003cU\u003e(self) -\u003e Result\u003cT, U\u003e\n    where\n        E: Into\u003cU\u003e,\n    {\n        self.map_err(Into::into)\n    }\n}\n```\n\nThis is useful when migrate from an inherent impl to an extension trait.\n\nNote that the visibility of all the associated items in the `impl` must be identical.\n\nNote that you cannot specify impl-level visibility and associated-item-level visibility at the same time.\n\n### [Supertraits](https://doc.rust-lang.org/reference/items/traits.html#supertraits)\n\nIf you want the extension trait to be a subtrait of another trait,\nadd `Self: SubTrait` bound to the `where` clause.\n\n```rust\nuse easy_ext::ext;\n\n#[ext(Ext)]\nimpl\u003cT\u003e T\nwhere\n    Self: Default,\n{\n    fn method(\u0026self) {}\n}\n```\n\n### Supported items\n\n#### [Associated functions (methods)](https://doc.rust-lang.org/reference/items/associated-items.html#associated-functions-and-methods)\n\n```rust\nuse easy_ext::ext;\n\n#[ext]\nimpl\u003cT\u003e T {\n    fn method(\u0026self) {}\n}\n```\n\n#### [Associated constants](https://doc.rust-lang.org/reference/items/associated-items.html#associated-constants)\n\n```rust\nuse easy_ext::ext;\n\n#[ext]\nimpl\u003cT\u003e T {\n    const MSG: \u0026'static str = \"Hello!\";\n}\n```\n\n#### [Associated types](https://doc.rust-lang.org/reference/items/associated-items.html#associated-types)\n\n```rust\nuse easy_ext::ext;\n\n#[ext]\nimpl str {\n    type Owned = String;\n\n    fn method(\u0026self) -\u003e Self::Owned {\n        self.to_owned()\n    }\n}\n```\n\n[rfc0445]: https://rust-lang.github.io/rfcs/0445-extension-trait-conventions.html\n\n\u003c!-- tidy:sync-markdown-to-rustdoc:end --\u003e\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":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaiki-e%2Feasy-ext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftaiki-e%2Feasy-ext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaiki-e%2Feasy-ext/lists"}