{"id":22942414,"url":"https://github.com/stardustdl/linq-in-rust","last_synced_at":"2025-04-07T06:06:07.015Z","repository":{"id":39861954,"uuid":"170080417","full_name":"StardustDL/Linq-in-Rust","owner":"StardustDL","description":"Language Integrated Query in Rust.","archived":false,"fork":false,"pushed_at":"2023-11-16T12:33:38.000Z","size":34,"stargazers_count":136,"open_issues_count":4,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T05:05:15.386Z","etag":null,"topics":["iterator","iterator-functions","linq","linq-methods","rust"],"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/StardustDL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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}},"created_at":"2019-02-11T06:40:25.000Z","updated_at":"2025-03-24T16:34:57.000Z","dependencies_parsed_at":"2024-11-08T10:33:32.296Z","dependency_job_id":"f2528300-70e0-483d-9390-1d1e98063212","html_url":"https://github.com/StardustDL/Linq-in-Rust","commit_stats":{"total_commits":13,"total_committers":2,"mean_commits":6.5,"dds":0.07692307692307687,"last_synced_commit":"1dea704e3b92606ce338d3be442c385f187e9adc"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StardustDL%2FLinq-in-Rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StardustDL%2FLinq-in-Rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StardustDL%2FLinq-in-Rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StardustDL%2FLinq-in-Rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StardustDL","download_url":"https://codeload.github.com/StardustDL/Linq-in-Rust/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247601447,"owners_count":20964864,"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":["iterator","iterator-functions","linq","linq-methods","rust"],"created_at":"2024-12-14T13:47:45.761Z","updated_at":"2025-04-07T06:06:06.992Z","avatar_url":"https://github.com/StardustDL.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Linq in Rust\n\n![CI](https://github.com/StardustDL/Linq-in-Rust/workflows/CI/badge.svg)\n[![](https://img.shields.io/librariesio/github/StardustDL/Linq-in-Rust.svg)](https://libraries.io/cargo/linq)\n[![](https://img.shields.io/crates/v/linq.svg)](https://crates.io/crates/linq)\n[![](https://img.shields.io/crates/v/linq.svg?label=docs\u0026\u0026colorA=blue)](https://docs.rs/linq/)\n![](https://img.shields.io/crates/d/linq.svg)\n![](https://img.shields.io/crates/l/linq.svg)\n[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/StardustDL/Linq-in-Rust.svg)](http://isitmaintained.com/project/StardustDL/Linq-in-Rust \"Average time to resolve an issue\")\n[![Percentage of issues still open](http://isitmaintained.com/badge/open/StardustDL/Linq-in-Rust.svg)](http://isitmaintained.com/project/StardustDL/Linq-in-Rust \"Percentage of issues still open\")\n\nLanguage Integrated Query in Rust (created by declarative macros).\n\n- Inspired by [LINQ in .NET](https://docs.microsoft.com/en-us/dotnet/csharp/linq/).\n- [What's LINQ](https://en.wikipedia.org/wiki/Language_Integrated_Query)\n\n**This project is under development!** API might be **changed**.\n\n## Quick Start\n\nThis is an example:\n\n```rust\nuse linq::linq;\nuse linq::Queryable;\n\nfn try_linq_methods() {\n    let x = 1..100;\n    let mut y: Vec\u003ci32\u003e = x.clone().filter(|p| p \u003c= \u00265).collect();\n    y.sort_by_key(|t| -t);\n    let y: Vec\u003ci32\u003e = y.into_iter().map(|t| t * 2).collect();\n    let e: Vec\u003ci32\u003e = x\n        .clone()\n        .where_by(|p| p \u003c= \u00265)\n        .order_by(|p| -p)\n        .select(|p| p * 2)\n        .collect();\n    assert_eq!(e, y);\n}\n\nfn try_linq_expr() {\n    let x = 1..100;\n    let mut y: Vec\u003ci32\u003e = x.clone().filter(|p| p \u003c= \u00265).collect();\n    y.sort_by_key(|t| -t);\n    let y: Vec\u003ci32\u003e = y.into_iter().map(|t| t * 2).collect();\n    let e: Vec\u003ci32\u003e =\n        linq!(from p in x.clone(), where p \u003c= \u00265, orderby -p, select p * 2).collect();\n    assert_eq!(e, y);\n}\n```\n\nIf you are familier with LINQ in C#, you will find this is easy to use.\n\n## Usage\n\nThe two imports is necessary:\n\n```rust\nuse linq::linq;         // for `linq!` macro\nuse linq::iter::Enumerable;    // for LINQ methods and `linq!` macro\n```\n\n### Methods\n\nThe trait `linq::Queryable` supports LINQ methods on `Iterator`. You can find the correspondences below.\n\n- Normal items mean they are builtin methods of `Iterator` in std.\n- **Bold** items mean they are implemented in this project. You can find them in module `linq::iter` (but they are private so that you can't import them).\n- *Italic* items mean they are not in roadmap. Happy for your suggestions.\n\n-----\n\n- [x] where =\u003e **where_by** =\u003e filter\n- [x] **select** =\u003e map\n- [x] select_many =\u003e **select_many_single, select_many**\n- [x] skip\n- [x] skip_while\n- [x] take\n- [x] take_while\n- [ ] join\n- [ ] *group_join*\n- [x] **concate** =\u003e chain\n- [x] **order_by**\n- [x] **order_by_descending**\n- [ ] *then_by*\n- [ ] *then_by_descending*\n- [x] **reverse** =\u003e rev\n- [ ] *group_by*\n- [x] distinct\n- [x] union\n- [ ] *intersect*\n- [ ] *except*\n- [x] **first** =\u003e next\n- [x] **single**\n- [x] **element_at** =\u003e nth\n- [x] all\n- [x] any\n- [x] **contains**\n- [x] count\n- [x] sum\n- [x] product\n- [x] min\n- [x] max\n- [ ] *average*\n- [ ] **aggregate** =\u003e fold\n\n### Expressions\n\nThe query expression begins with `from` clause and ends with `select` clause. Use `,` to seperate every clause.\n\n```rust\nlinq!(from x in coll, select x)\n```\n\nNow we supports these keywords:\n\n- [x] from\n  - [x] from (`select_many_single`)\n  - [x] zfrom (`select_many`)\n- [x] in\n- [x] select\n- [x] where\n- [x] orderby\n- [x] descending\n- [ ] group_by\n- [ ] more...\n\n### From\n\n```rust\nfrom \u003cid\u003e in \u003citer expr\u003e,\n```\n\nAlso you can enumerate elements of each set in the collection (Attention: for this type, you can't access the value that is in the first `from` clause in `select` clause):\n\n```rust\nlet x = 1..5;\nlet y = vec![0, 0, 1, 0, 1, 2, 0, 1, 2, 3];\nlet e: Vec\u003ci32\u003e = linq!(from p in x.clone(), from t in 0..p, select t).collect();\n\nassert_eq!(e, y);\n```\n\nIf you want to zip or enumerate value-pairs of two sets, use `zfrom` for the second `from`:\n\n```rust\nlet x = 1..5;\nlet y = vec![\n    (1, 0),\n    (2, 0),\n    (2, 1),\n    (3, 0),\n    (3, 1),\n    (3, 2),\n    (4, 0),\n    (4, 1),\n    (4, 2),\n    (4, 3),\n];\nlet e: Vec\u003c_\u003e = linq!(from p in x.clone(), zfrom t in 0..p, select (p,t)).collect();\n\nassert_eq!(e, y);\n```\n\nThe expression in `zfrom` recieve the cloned value in the first `from`,\nand the elements in two sets will be cloned for `select` clause.\n\n### Where\n\n```rust\nwhile \u003cexpr\u003e,\n```\n\nYou can use `where` clause in single-from query, and the expression will recieve a variable named the `id` in `from` clause. The expression need to return a boolean value.\n\n### Orderby\n\n```rust\norderby \u003cexpr\u003e,\norderby \u003cexpr\u003e, descending,\n```\n\nYou can use `orderby` clause in single-from query. This query will collect the iterator, and sort them by the expression, then return the new iterator.\n\n## Development\n\nWe need more unit-test samples. If you have any ideas, open issues to tell us.\n\nSince the expression procedural macros is not stable, I only create macros by declarative macros.\n\n```sh\n$ cargo test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstardustdl%2Flinq-in-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstardustdl%2Flinq-in-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstardustdl%2Flinq-in-rust/lists"}