diff --git a/.github/workflows/ci_bindings_dart.yml b/.github/workflows/ci_bindings_dart.yml index a3b558618c2..f874d9ddaf4 100644 --- a/.github/workflows/ci_bindings_dart.yml +++ b/.github/workflows/ci_bindings_dart.yml @@ -76,5 +76,4 @@ jobs: - name: test working-directory: bindings/dart run: | - dart run lib/opendal_test.dart - + dart run tests/opendal_test.dart diff --git a/bindings/dart/README.md b/bindings/dart/README.md index 00a4be32656..dd82802de03 100644 --- a/bindings/dart/README.md +++ b/bindings/dart/README.md @@ -1,5 +1,47 @@ # 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 ``` @@ -7,10 +49,12 @@ 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 , 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 diff --git a/bindings/dart/examples/basic.dart b/bindings/dart/examples/basic.dart new file mode 100644 index 00000000000..9ab8a5dfb71 --- /dev/null +++ b/bindings/dart/examples/basic.dart @@ -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())); +} diff --git a/bindings/dart/lib/opendal.dart b/bindings/dart/lib/opendal.dart index 6ea4f691b4f..d7ceefa116e 100644 --- a/bindings/dart/lib/opendal.dart +++ b/bindings/dart/lib/opendal.dart @@ -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; diff --git a/bindings/dart/lib/opendal_test.dart b/bindings/dart/tests/opendal_test.dart similarity index 93% rename from bindings/dart/lib/opendal_test.dart rename to bindings/dart/tests/opendal_test.dart index fcbe720a5fb..ee1c570638e 100644 --- a/bindings/dart/lib/opendal_test.dart +++ b/bindings/dart/tests/opendal_test.dart @@ -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', () {