rust 3.1.0 copy "rust: ^3.1.0" to clipboard
rust: ^3.1.0 copied to clipboard

A pure Dart implementation of Rust patterns. Types include Result, Option, Cell, Slice, Array, Iterator, Channels, Mutex, Path, etc.

Pub Version Dart Package Docs License: MIT Build Status

rust (formally known as rust_core) is a pure Dart implementation of patterns found in the Rust programming language, bringing powerful tools previously only available to Rust developers to Dart developers!

New types include Result, Option, Cell, Slice, Array, Iterator, Channels, Mutex, Path and more.

See the Documentation Book 📖 for a deeper dive!

Example: Rust Language vs rust Package #


Goal: Get the index of every "!" in a string not followed by a "?"

Rust:

use std::iter::Peekable;

fn main() {
  let string = "kl!sd!?!";
  let mut answer: Vec<usize> = Vec::new();
  let mut iter: Peekable<_> = string
      .chars()
      .map_windows(|w: &[char; 2]| *w)
      .enumerate()
      .peekable();

  while let Some((index, window)) = iter.next() {
      match window {
          ['!', '?'] => continue,
          ['!', _] => answer.push(index),
          [_, '!'] if iter.peek().is_none() => answer.push(index + 1),
          _ => continue,
      }
  }
  println!("{:?}", answer); // [2, 7]
}
copied to clipboard

Dart:

import 'package:rust/rust.dart';

void main() {
  final string = "kl!sd!?!";
  Vec<int> answer = [];
  Peekable<(int, Arr<String>)> iter = string
      .chars()
      .mapWindows(2, identity)
      .enumerate()
      .peekable();

  while (iter.moveNext()) {
    final (index, window) = iter.current;
    switch (window) {
      case ["!", "?"]:
        break;
      case ["!", _]:
        answer.push(index);
      case [_, "!"] when iter.peek() == null: // or `iter.peekOpt().isNone()`
        answer.push(index + 1);
    }
  }
  print(answer); // [2, 7]
}
copied to clipboard

Project Goals #

rust's primary goal is to give Dart developers access to powerful tools previously only available to Rust developers.

To accomplish this, Rust's functionalities are carefully adapted to Dart's paradigms, focusing on a smooth idiomatic language-compatible integration. The result is developers now have a whole new toolset to tackle problems in Dart.

True to the Rust philosophy, rust strives to bring reliability and performance in every feature. Every feature is robustly tested. Over 500 meaningful test suites and counting.

13
likes
150
points
385
downloads

Publisher

verified publishervoyver.com

Weekly Downloads

2024.09.21 - 2025.04.05

A pure Dart implementation of Rust patterns. Types include Result, Option, Cell, Slice, Array, Iterator, Channels, Mutex, Path, etc.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

meta, path

More

Packages that depend on rust