Download Latest Version v3.1.0 source code.tar.gz (170.7 kB)
Email in envelope

Get an email when there's a new version of rust_core

Home / v1.3.0
Name Modified Size InfoDownloads / Week
Parent folder
README.md 2024-08-06 2.4 kB
v1.3.0 source code.tar.gz 2024-08-06 155.8 kB
v1.3.0 source code.zip 2024-08-06 211.8 kB
Totals: 3 Items   370.1 kB 0

LazyCellAsync

A value which is asynchronously initialized on the first access.

:::dart
int callCount = 0;
final lazyCell = LazyCellAsync<int>(() async {
  callCount++;
  return 20;
});
final firstCall = await lazyCell.force();
expect(callCount, equals(1));
expect(firstCall, equals(20));
final secondCall = lazyCell(); // Could also call `await lazyCell.force()` again.
expect(callCount, equals(1));
expect(secondCall, equals(20));

RIterator Renamed to Iter

RIterator was renamed to Iter. RIterator is now a deprecated typedef of Iter (for backwards compatibility).

:::dart
List<int> list = [1, 2, 3, 4, 5];
Iter<int> filtered = list.iter().filterMap((e) {
  if (e % 2 == 0) {
    return Some(e * 2);
  }
  return None;
});
expect(filtered, [4, 8]);

Vec

Vec adds additional extension methods for List and adds a Vec type - a typedef of List. Vec is used to specifically denote a contiguous growable array, unlike List which is growable or non-growable, which may cause runtime exceptions. Vec being a typedef of List means it can be used completely interchangeably.

:::dart
Vec<int> vec = [1, 2, 3, 4];
// easily translate back and forth
List<int> list = vec;
vec = list;

Vec is a nice compliment to Arr (array) type. Vec is not included in 'package:rust_core/rust_core.dart' instead it is included included in 'package:rust_core/vec.dart'.

Usage

:::dart
import 'package:rust_core/rust_core.dart';
import 'package:rust_core/vec.dart';

void main() {
  Vec<int> vec = [1, 2, 3, 4];

  Vec<int> replaced = vec.splice(1, 3, [5, 6]);
  print(replaced); // [2, 3]
  print(vec); // [1, 5, 6, 4]

  vec.push(5);
  vec.insert(2, 99);

  int removed = vec.removeAt(1);
  print(removed); // 5
  print(vec); // [1, 99, 6, 4, 5]

  vec.resize(10, 0);
  print(vec); // [1, 99, 6, 4, 5, 0, 0, 0, 0, 0]

  Iter<int> iterator = vec.extractIf((element) => element % 2 == 0);
  Vec<int> extracted = iterator.collectVec();
  print(extracted); // [6, 4, 0, 0, 0, 0, 0]
  print(vec); // [1, 99, 5]

  Slice<int> slice = vec.asSlice();
}

Full Changelog: https://github.com/mcmah309/rust_core/compare/v1.2.0...v1.3.0

Source: README.md, updated 2024-08-06