{"id":22751964,"url":"https://github.com/aandreba/fast_async_trait","last_synced_at":"2025-03-30T06:43:26.908Z","repository":{"id":63816338,"uuid":"570968724","full_name":"Aandreba/fast_async_trait","owner":"Aandreba","description":"Fast async traits for Rust","archived":false,"fork":false,"pushed_at":"2022-11-26T19:53:37.000Z","size":17,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-06T00:08:57.736Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/Aandreba.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-11-26T18:10:18.000Z","updated_at":"2024-02-25T07:32:54.000Z","dependencies_parsed_at":"2022-11-26T19:32:42.142Z","dependency_job_id":null,"html_url":"https://github.com/Aandreba/fast_async_trait","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aandreba%2Ffast_async_trait","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aandreba%2Ffast_async_trait/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aandreba%2Ffast_async_trait/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aandreba%2Ffast_async_trait/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Aandreba","download_url":"https://codeload.github.com/Aandreba/fast_async_trait/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246285668,"owners_count":20752953,"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":[],"created_at":"2024-12-11T05:09:11.890Z","updated_at":"2025-03-30T06:43:26.892Z","avatar_url":"https://github.com/Aandreba.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fast Async Trait\nLibrary to implement async traits that aren't reliant on boxed futures, relying instead on the `type_alias_impl_trait` nightly feature for it's base implementation.\n\n## Limitations\n- Currently, only one lifetime per async function is allowed\n```rust\npub trait AsyncTrait {\n    // allowed\n    async fn test1 (\u0026self, right: u8);\n    // allowed\n    async fn test2 (\u0026self, right: \u0026u8);\n    // allowed\n    async fn test3\u003c'b\u003e (\u0026'b self, right: \u0026'b u8);\n    // compiler error\n    async fn test4\u003c'b\u003e (\u0026self, right: \u0026'b u8);\n}\n```\n- Async functions with `Self: Rc\u003cSelf\u003e` and similar aren't currently supported\n\n## Example\n```rust\n#![feature(type_alias_impl_trait)]\n\nuse fast_async_trait::*;\n\n#[async_trait_def]\npub trait AsyncTrait {\n    type Item;\n\n    async fn owned (self) -\u003e Option\u003cSelf::Item\u003e;\n    async fn by_ref (\u0026self) -\u003e Option\u003cSelf::Item\u003e;\n    async fn by_mut (\u0026mut self) -\u003e Option\u003cSelf::Item\u003e;\n    \n    #[inline]\n    async fn owned_default (self, _n: usize) -\u003e Option\u003cSelf::Item\u003e where Self: Sized {\n        return self.owned().await\n    }\n\n    #[inline]\n    async fn by_ref_default (\u0026self, n: usize) -\u003e Option\u003cSelf::Item\u003e {\n        for _ in 0..n {\n            let _ = self.by_ref().await;\n        }\n        return self.by_ref().await\n    }\n\n    #[inline]\n    async fn by_mut_default (\u0026mut self, n: usize) -\u003e Option\u003cSelf::Item\u003e {\n        for _ in 0..n {\n            let _ = self.by_mut().await;\n        }\n        return self.by_mut().await\n    }\n}\n\n#[async_trait_impl]\nimpl AsyncTrait for (usize, \u0026[u8]) {\n    type Item = u8;\n\n    async fn owned (self) -\u003e Option\u003cSelf::Item\u003e {\n        return self.1.get(self.0).copied()\n    }\n\n    #[inline]\n    async fn by_ref (\u0026self) -\u003e Option\u003cSelf::Item\u003e {\n        return self.1.get(self.0).copied()\n    }\n\n    #[inline]\n    async fn by_mut (\u0026mut self) -\u003e Option\u003cSelf::Item\u003e {\n        let v = self.1.get(self.0).copied();\n        self.0 += 1;\n        return v;\n    }\n}\n```\n\n## Nightly features\n\nThe `type_alias_impl_trait` nightly feature is required to be able to add `impl Trait` types (in our case, `impl Future` types) as associated generic types of a trait, which this crate relies on.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faandreba%2Ffast_async_trait","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faandreba%2Ffast_async_trait","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faandreba%2Ffast_async_trait/lists"}