ProductPromotion
Logo

Rust

made by https://0x3d.site

GitHub - StardustDL/Linq-in-Rust: Language Integrated Query in Rust.
Language Integrated Query in Rust. Contribute to StardustDL/Linq-in-Rust development by creating an account on GitHub.
Visit Site

GitHub - StardustDL/Linq-in-Rust: Language Integrated Query in Rust.

GitHub - StardustDL/Linq-in-Rust: Language Integrated Query in Rust.

Linq in Rust

CI Average time to resolve an issue Percentage of issues still open

Language Integrated Query in Rust (created by declarative macros).

This project is under development! API might be changed.

Quick Start

This is an example:

use linq::linq;
use linq::Queryable;

fn try_linq_methods() {
    let x = 1..100;
    let mut y: Vec<i32> = x.clone().filter(|p| p <= &5).collect();
    y.sort_by_key(|t| -t);
    let y: Vec<i32> = y.into_iter().map(|t| t * 2).collect();
    let e: Vec<i32> = x
        .clone()
        .where_by(|p| p <= &5)
        .order_by(|p| -p)
        .select(|p| p * 2)
        .collect();
    assert_eq!(e, y);
}

fn try_linq_expr() {
    let x = 1..100;
    let mut y: Vec<i32> = x.clone().filter(|p| p <= &5).collect();
    y.sort_by_key(|t| -t);
    let y: Vec<i32> = y.into_iter().map(|t| t * 2).collect();
    let e: Vec<i32> =
        linq!(from p in x.clone(), where p <= &5, orderby -p, select p * 2).collect();
    assert_eq!(e, y);
}

If you are familier with LINQ in C#, you will find this is easy to use.

Usage

The two imports is necessary:

use linq::linq;         // for `linq!` macro
use linq::iter::Enumerable;    // for LINQ methods and `linq!` macro

Methods

The trait linq::Queryable supports LINQ methods on Iterator. You can find the correspondences below.

  • Normal items mean they are builtin methods of Iterator in std.
  • 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).
  • Italic items mean they are not in roadmap. Happy for your suggestions.

  • where => where_by => filter
  • select => map
  • select_many => select_many_single, select_many
  • skip
  • skip_while
  • take
  • take_while
  • join
  • group_join
  • concate => chain
  • order_by
  • order_by_descending
  • then_by
  • then_by_descending
  • reverse => rev
  • group_by
  • distinct
  • union
  • intersect
  • except
  • first => next
  • single
  • element_at => nth
  • all
  • any
  • contains
  • count
  • sum
  • product
  • min
  • max
  • average
  • aggregate => fold

Expressions

The query expression begins with from clause and ends with select clause. Use , to seperate every clause.

linq!(from x in coll, select x)

Now we supports these keywords:

  • from
    • from (select_many_single)
    • zfrom (select_many)
  • in
  • select
  • where
  • orderby
  • descending
  • group_by
  • more...

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![0, 0, 1, 0, 1, 2, 0, 1, 2, 3];
let e: Vec<i32> = linq!(from p in x.clone(), from t in 0..p, select t).collect();

assert_eq!(e, y);

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![
    (1, 0),
    (2, 0),
    (2, 1),
    (3, 0),
    (3, 1),
    (3, 2),
    (4, 0),
    (4, 1),
    (4, 2),
    (4, 3),
];
let e: Vec<_> = linq!(from p in x.clone(), zfrom t in 0..p, select (p,t)).collect();

assert_eq!(e, y);

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.

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.

$ cargo test

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory