JonasKruckenberg / tauri-sys

Bindings to the Tauri API for projects using wasm-bindgen
Apache License 2.0
84 stars 21 forks source link

Fixing Opaque Return Type Conflict in `pick_folders` and `pick_files` Method #28

Open Mouradost opened 11 months ago

Mouradost commented 11 months ago

Related to #27

Purpose

This pull request addresses an issue in the pick_folders and pick_files methods of the tauri-sys crate, where a conflicting opaque return type is causing build failures. The changes proposed here aim to resolve the conflict and ensure the method returns a consistent and correct opaque type.

Problem

The current implementation of the pick_folders and pick_files method returns an opaque type representing an iterator of PathBuf items. However, the closure passed to the map function within the method is causing a mismatch in the concrete return type for the same opaque type, leading to a build failure.

Solution

To fix the conflict, we have explicitly defined a trait, PathBufIterator, to represent the iterator of PathBufitems. We have then implemented this trait for the actual iterator type, std::vec::IntoIter<PathBuf>, used within the method. By wrapping the closure inside a function that returns a trait object (Box<dyn PathBufIterator>), we ensure a consistent return type for the opaque type, resolving the conflict.

Proposed Changes

Introduced the PathBufIterator trait to represent the iterator of PathBuf items. Implemented the PathBufIterator trait for the actual iterator type used within the pick_folders and pick_files methods. Modified the closure passed to the map function to explicitly return a trait object (Box<dyn PathBufIterator>).

Testing

The crate tauri-sys has been build and tested on the three operating systems (Windows, Ubuntu, and macOS). The tests verify that the method returns the correct iterator and that it integrates seamlessly with the existing codebase.

Documentation

Only comments are provided. However, if the pull request get accepted I will provide proper documentation.