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

Allow the main function in Rust to have any return type #394

Merged
merged 1 commit into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions rust_crate/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ pub struct DartSignal<T> {
/// the `Runtime` object itself might be moved between threads,
/// along with all the tasks it manages.
#[cfg(not(target_family = "wasm"))]
pub fn start_rust_logic<F>(main_future: F) -> Result<(), RinfError>
pub fn start_rust_logic<F, T>(main_future: F) -> Result<(), RinfError>
where
F: Future<Output = ()> + Send + 'static,
F: Future<Output = T> + Send + 'static,
T: Send + 'static,
{
start_rust_logic_real(main_future)
}
Expand All @@ -40,7 +41,7 @@ where
#[cfg(target_family = "wasm")]
pub fn start_rust_logic<F>(main_future: F) -> Result<(), RinfError>
where
F: Future<Output = ()> + 'static,
F: Future + 'static,
{
start_rust_logic_real(main_future)
}
Expand Down
5 changes: 3 additions & 2 deletions rust_crate/src/interface_os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ pub extern "C" fn prepare_isolate_extern(port: i64) {
type ShutdownSenderLock = OnceLock<ThreadLocal<RefCell<Option<ShutdownSender>>>>;
static SHUTDOWN_SENDER: ShutdownSenderLock = OnceLock::new();

pub fn start_rust_logic_real<F>(main_future: F) -> Result<(), RinfError>
pub fn start_rust_logic_real<F, T>(main_future: F) -> Result<(), RinfError>
where
F: Future<Output = ()> + Send + 'static,
F: Future<Output = T> + Send + 'static,
T: Send + 'static,
{
// Enable backtrace output for panics.
#[cfg(debug_assertions)]
Expand Down
6 changes: 4 additions & 2 deletions rust_crate/src/interface_web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use wasm_bindgen_futures::spawn_local;

pub fn start_rust_logic_real<F>(main_future: F) -> Result<(), RinfError>
where
F: Future<Output = ()> + 'static,
F: Future + 'static,
{
// Add kind description for panics.
#[cfg(debug_assertions)]
Expand All @@ -17,7 +17,9 @@ where
}

// Run the main function.
spawn_local(main_future);
spawn_local(async {
main_future.await;
});

Ok(())
}
Expand Down