Skip to content

Commit

Permalink
feat(binding/dart): add examples, tests (#5740)
Browse files Browse the repository at this point in the history
* add examples, tests

* re-export file

* typo

* add license header

* typo
  • Loading branch information
asukaminato0721 authored Mar 11, 2025
1 parent e090311 commit a77843c
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 7 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci_bindings_dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,4 @@ jobs:
- name: test
working-directory: bindings/dart
run: |
dart run lib/opendal_test.dart
dart run tests/opendal_test.dart
48 changes: 46 additions & 2 deletions bindings/dart/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,60 @@
# Apache OpenDAL™ Dart Binding (WIP)

## Useful Links

- [Examples](./examples)

## Usage

Api is designed to be like stdlib style.

This is stdlib

```
import 'dart:io';
void main() async {
final file = File('file.txt');
var is_exists = await file.exists();
print(is_exists);
}
```

This is opendal

```
import 'opendal.dart';
void main() async {
await RustLib.init();
final File = FileManager.initOp(schemeStr: "fs", map: {"root": "/tmp"});
// drop-in
final file = File('file.txt');
var is_exists = await file.exists();
print(is_exists);
}
```

## Test

```
dart run tests/opendal_test.dart
```

## Development

```
flutter pub get
flutter_rust_bridge_codegen generate
cd rust
cargo build -r
cd ..
dart run lib/opendal_test.dart
```

## Update generated code

This binding uses <https://github.com/fzyzcjy/flutter_rust_bridge>, when updating the codegen. First check `FLUTTER_RUST_BRIDGE_CODEGEN_VERSION`, then pin the version of `flutter_rust_bridge` in `pubspec.yaml` and `rust/Cargo.toml`. Make sure the runtime versions are matched.

## License and Trademarks

Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
Expand Down
26 changes: 26 additions & 0 deletions bindings/dart/examples/basic.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import '../lib/opendal.dart';

void main() async {
await RustLib.init();
final File = FileManager.initOp(schemeStr: "fs", map: {"root": "/tmp"});
// drop-in style
var testFile = File("test_1.txt");
assert(!(await testFile.exists()));
}
19 changes: 19 additions & 0 deletions bindings/dart/lib/opendal.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import 'src/rust/frb_generated.dart';
import 'src/rust/api/opendal_api.dart';
export 'src/rust/frb_generated.dart';
export 'src/rust/api/opendal_api.dart';

class FileManager {
final Operator _operator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import 'package:test/test.dart';
import 'src/rust/frb_generated.dart';
import 'src/rust/api/opendal_api.dart';
import 'opendal.dart';
import '../lib/opendal.dart';

void main() {
group('opendal unit test', () {
Expand Down

0 comments on commit a77843c

Please # to comment.