Doubt about rust logic #79
Replies: 7 comments 5 replies
-
Hi @hareendranmg, that's a really good question. Rust's restart on Dart's hot restart was temporarily gone on 2.1 and 2.2. It was restored in 2.3. If you install version 2.3 and do However, there is a caveat that Rust logic does not get restarted yet on the web. We're trying to solve this problem, which will probably be shipped with 2.4 or beyond. If you have any other problems, please let us know! |
Beta Was this translation helpful? Give feedback.
-
Hmm, that sounds strange. When Dart performs hot restart, the whole async tokio runtime in Rust should stop immediately. May I ask you if it was surely hot restart was what you did, not hot reload? Because those two are similar but different: If you've correctly done Dart's hot restart, can you check that no attribute is above Also, to make things sure, could you copy and paste the content of |
Beta Was this translation helpful? Give feedback.
-
When I perform hot restart, the output in the terminal is as follows:
This is the code: // native/hub/src/sample_functions.rs
pub async fn keep_drawing_mandelbrot() {
let mut scale: f64 = 1.0;
let mut interval = crate::time::interval(std::time::Duration::from_millis(1000));
loop {
use std::time::{SystemTime, UNIX_EPOCH};
if let Ok(duration) = SystemTime::now().duration_since(UNIX_EPOCH) {
let seconds_since_epoch = duration.as_secs();
crate::print!("Current time: {} seconds since epoch", seconds_since_epoch);
} else {
crate::print!("Error: Failed to get the current time.");
}
interval.tick().await;
scale *= 0.95;
if scale < 1e-7 {
scale = 1.0
};
let calculated = sample_crate::mandelbrot(
sample_crate::Size {
width: 64,
height: 64,
},
sample_crate::Point {
x: 0.360,
y: -0.641,
},
scale,
4,
);
if let Ok(mandelbrot) = calculated {
let rust_signal = RustSignal {
address: String::from("sampleCategory.mandelbrot"),
bytes: mandelbrot,
};
send_rust_signal(rust_signal);
}
}
} It looks like the whole async tokio runtime is properly terminated and restarted upon Dart's hot restart to me, as the previous print loop does disappear. If the previous print loop did remain, there should be accumulated prints every second, but there's not. If you don't mind, could you provide an elaborated description of how you are using |
Beta Was this translation helpful? Give feedback.
-
Hi @temeddix, I believe there might be a misunderstanding regarding how Rust logic interacts with Flutter restarts. Can you kindly clarify the following doubts for me? In my Flutter code, I am incrementing the count variable value. However, upon restarting the Flutter application, the count variable is reset to 0. On the Rust side, if I change the increment value from 7 to 10 as shown below:
|
Beta Was this translation helpful? Give feedback.
-
Oh, I now understand what made the confusion. The updated Rust code cannot be loaded upon Dart's hot restart. To incorporate the changes, the app needs to be re-compiled, as the app binary must be linked to the newly compiled Rust library files again. This limitation arises from the Rust compilation process, as Rust does not inherently support a hot restart feature. Thank you for the heads-up, I will include this in the guides soon! |
Beta Was this translation helpful? Give feedback.
-
Hi @temeddix, Is there any other ways to incorporate the updated Rust code changes other than re-compilation, like some sort of cargo build like that? |
Beta Was this translation helpful? Give feedback.
-
Thanks @temeddix. |
Beta Was this translation helpful? Give feedback.
-
Hi team,
In one of the ealier commit, there is a point about restarting Rust logic on Dart's hot restart. Is that possible? As of now i can't restart the Rust logic from Dart's hot restart.
Please find the commit details here
Beta Was this translation helpful? Give feedback.
All reactions