Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bindings/dart): Add dart binding #5591

Open
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

asukaminato0721
Copy link
Contributor

@asukaminato0721 asukaminato0721 commented Feb 1, 2025

Which issue does this PR close?

Closes #2435. Use the same way as https://github.com/open-spaced-repetition/fsrs-rs-dart.

Rationale for this change

What changes are included in this PR?

add dart binding

Are there any user-facing changes?

no

@asukaminato0721 asukaminato0721 changed the title init add dart binding Feb 1, 2025
@asukaminato0721 asukaminato0721 marked this pull request as ready for review February 1, 2025 11:23
@asukaminato0721 asukaminato0721 changed the title add dart binding feat(bindings/dart): Add dart binding Feb 1, 2025
@asukaminato0721 asukaminato0721 marked this pull request as draft February 1, 2025 15:37
@asukaminato0721
Copy link
Contributor Author

asukaminato0721 commented Feb 1, 2025

I only ported part of the apis so the test can pass. And currently all result is using unwrap (as a first version).

@asukaminato0721 asukaminato0721 marked this pull request as ready for review February 1, 2025 19:38
@Xuanwo
Copy link
Member

Xuanwo commented Feb 2, 2025

Thank you so much, @asukaminato0721, for working on this. I will start reviewing this PR later next week. Wishing you a wonderful holiday in the meantime!

.github/workflows/ci_bindings_dart.yml Outdated Show resolved Hide resolved
.github/workflows/ci_bindings_dart.yml Outdated Show resolved Hide resolved
.github/workflows/ci_bindings_dart.yml Outdated Show resolved Hide resolved
.github/workflows/ci_bindings_dart.yml Outdated Show resolved Hide resolved
bindings/dart/README.md Outdated Show resolved Hide resolved
bindings/dart/lib/src/rust/api/opendal_api.dart Outdated Show resolved Hide resolved
bindings/dart/pubspec.yaml Outdated Show resolved Hide resolved
bindings/dart/pubspec.yaml Outdated Show resolved Hide resolved
licenserc.toml Outdated Show resolved Hide resolved
bindings/dart/rust/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines 147 to 176
abstract class Operator implements RustOpaqueInterface {
Capability capability();

Future<void> check();

Future<void> createDir({required String path});

void createDirSync({required String path});

Future<void> delete({required String path});

void deleteSync({required String path});

Future<bool> isExist({required String path});

bool isExistSync({required String path});

factory Operator(
{required String schemeStr, required Map<String, String> map}) =>
RustLib.instance.api
.crateApiOpendalApiOperatorNew(schemeStr: schemeStr, map: map);

Future<void> rename({required String from, required String to});

void renameSync({required String from, required String to});

Future<Metadata> stat({required String path});

Metadata statSync({required String path});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that we are following the same way of rust's API. Does dart use this same API pattern? Maybe we can take it's fs API or s3 SDK for an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does dart use this same API pattern

yes, dart just change from like rename_sync to renameSync.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the lib/opendal_test.dart file, there are some test cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, sorry for not making my statement clearer. What I want to know is how native Dart users perceive these APIs. Does our current API design meet their expectations?

For example, dart-io's API looks in this way: https://api.dart.dev/dart-io/dart-io-library.html

import 'dart:io';

void main() async {
  final filename = 'file.txt';
  var file = await File(filename).writeAsString('some content');
  // Do something with the file.
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get it. User can just import them and use them like native.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I'm afraid we're still not on the same page. What I want to ask is how users feel about this library—will it feel native to them? Will they appreciate this API design?

Take dart:io as an example. Should we expose a File class and provide methods like rename and write on it? Or is it a widely accepted API design pattern to have a struct that provides all the necessary APIs?

Finally, is it a good idea to introduce something called Operator in the Dart ecosystem? Do they have a similar concept?


In short, how will we design a native library in dart that allows users to access all storage services? Fortunately, it's powered by OpenDAL.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's take other bindings as examples:

  • Python expsoes File to users.
  • Java exposes InputStream and OutputStream to users.

What's the similiar concept in dart?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenDAL Dart/Flutter bindings
2 participants