Linq in Rust
Linq query in Rust (created by declarative macros).
- Inspired by LINQ in .NET.
- What's LINQ
This project is under development! API might be changed.
Quick Start
This is an example:
use linq;
If you are familier with LINQ in C#, you will find this is easy to use.
Usage
The query statement begins with from
clause and ends with select
clause. Use ,
to seperate every clause.
linq!
From
from <id> in <iter expr>,
Also 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):
let x = 1..5;
let y = vec!;
let e: = linq!.collect;
assert_eq!;
If you want to zip or enumerate value-pairs of two sets, use zfrom
for the second from
:
let x = 1..5;
let y = vec!;
let e: = linq!.collect;
assert_eq!;
The expression in zfrom
recieve the cloned value in the first from
,
and the elements in two sets will be cloned for select
clause.
Where
while <expr>,
You 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.
Orderby
orderby <expr>,
orderby <expr>, descending,
You 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.
Linq Keywords
- from
- from (child-from)
- zfrom (zip-from)
- in
- select
- where
- orderby
- descending
- group_by
- more...
Query Operators
All italic items mean they are not in roadmap. Happy for your suggestions.
All bold items mean they are implemented in this project. You can find them in module linq::ops
.
- where => where_by => filter
- select => select_one => map
- select_many => select_many, select_many_zip, select_two
- skip => skip
- skip_while => skip_while
- take => take
- take_while => take_while
- join
- group_join
- concate => chain
- order_by => order_by
- order_by_descending => order_by
- then_by
- then_by_descending
- reverse => rev
- group_by
- distinct
- union
- intersect
- except
- first => next
- single
- element_at => nth
- all => all
- any => any
- contains
- count => count
- sum
- min
- max
- average
- aggregate
Development
We need more unit-test samples. If you have any ideas, open issues to tell us.
Since the expression procedural macros is not stable, I only create macros by declarative macros.