{"id":33939169,"url":"https://github.com/tlowerison/scoped-futures","last_synced_at":"2026-04-07T04:31:40.783Z","repository":{"id":62870655,"uuid":"549904947","full_name":"tlowerison/scoped-futures","owner":"tlowerison","description":"Rust utility crate for imposing upper bounds on Future lifetimes.","archived":false,"fork":false,"pushed_at":"2024-10-07T21:49:55.000Z","size":37,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-14T03:24:43.563Z","etag":null,"topics":["rust","rust-traits"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/scoped-futures","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/tlowerison.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":"2022-10-11T23:18:54.000Z","updated_at":"2025-10-23T00:48:14.000Z","dependencies_parsed_at":"2023-02-01T01:45:56.368Z","dependency_job_id":null,"html_url":"https://github.com/tlowerison/scoped-futures","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tlowerison/scoped-futures","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlowerison%2Fscoped-futures","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlowerison%2Fscoped-futures/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlowerison%2Fscoped-futures/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlowerison%2Fscoped-futures/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tlowerison","download_url":"https://codeload.github.com/tlowerison/scoped-futures/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlowerison%2Fscoped-futures/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31500397,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-07T03:10:19.677Z","status":"ssl_error","status_checked_at":"2026-04-07T03:10:13.982Z","response_time":105,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["rust","rust-traits"],"created_at":"2025-12-12T15:15:01.505Z","updated_at":"2026-04-07T04:31:40.778Z","avatar_url":"https://github.com/tlowerison.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# scoped-futures\n\nA utility crate for imposing upper bounds on `Future` lifetimes. This is especially useful for callbacks that use higher-ranked lifetimes in their return type,\nwhere it can prevent `'static` bounds from being placed on a returned `Future`.\n\nThis crate is effectively a port of Sabrina Jewson's [better alternative to lifetime GATs](https://sabrinajewson.org/blog/the-better-alternative-to-lifetime-gats)\nfor Futures.\n\n## Example\n```rust\nuse core::pin::Pin;\nuse scoped_futures::{ScopedBoxFuture, ScopedFutureExt};\n\npub struct Db {\n    count: u8,\n}\n\nimpl Db {\n    async fn transaction\u003c'a, F, T, E\u003e(\u0026mut self, callback: F) -\u003e Result\u003cT, E\u003e\n    where\n        // ScopedBoxFuture imposes a lifetime bound on 'b which prevents the hrtb below needing\n        // to be satisfied for all lifetimes (including 'static) and instead only lifetimes\n        // which live at most as long as 'a\n        F: for\u003c'b /* where 'a: 'b */\u003e FnOnce(\u0026'b mut Self) -\u003e ScopedBoxFuture\u003c'a, 'b, Result\u003cT, E\u003e\u003e + Send + 'a,\n        T: 'a,\n        E: 'a,\n    {\n        callback(self).await\n    }\n}`\n\npub async fn test_transaction\u003c'a, 'b\u003e(\n    db: \u0026mut Db,\n    ok: \u0026'a str,\n    err: \u0026'b str,\n    is_ok: bool,\n) -\u003e Result\u003c\u0026'a str, \u0026'b str\u003e {\n    // note the lack of `move` or any cloning in front of the closure\n    db.transaction(|db| async move {\n        db.count += 1;\n        if is_ok {\n            Ok(ok)\n        } else {\n            Err(err)\n        }\n    }.scope_boxed()).await?;\n\n    // note that `async` can be used instead of `async move` since the callback param is unused\n    db.transaction(|_| async {\n        if is_ok {\n            Ok(ok)\n        } else {\n            Err(err)\n        }\n    }.scope_boxed()).await\n}\n\n#[test]\nfn test_transaction_works() {\n    futures::executor::block_on(async {\n        let mut db = Db { count: 0 };\n        let ok = String::from(\"ok\");\n        let err = String::from(\"err\");\n        let result = test_transaction(\u0026mut db, \u0026ok, \u0026err, true).await;\n        assert_eq!(ok, result.unwrap());\n        assert_eq!(1, db.count);\n    })\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftlowerison%2Fscoped-futures","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftlowerison%2Fscoped-futures","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftlowerison%2Fscoped-futures/lists"}