correct the update method to get the return type[Task<T>]

昨天用rustup更新了一下,不知道为什么连info都会提示我调了unsafe方法,要求我把它放进unsafe块中,日了狗,先记录一下再说吧
This commit is contained in:
z_lenovo 2025-06-28 19:54:11 +08:00
parent 656eceac07
commit 06549c35ab
7 changed files with 46 additions and 32 deletions

View File

@ -10,6 +10,7 @@ iced = { git = "https://github.com/iced-rs/iced.git", features = [
"advanced",
"image",
"sipper",
"tokio",
] }
tokio = { version = "1.45.1", features = ["full"] }
reqwest = "0.12.20"
@ -47,6 +48,8 @@ iced_futures = { version = "0.13.2", features = [
"thread-pool",
] }
num_enum = "0.7.4"
trace = "0.1.7"
tracing = "0.1.41"
[build-dependencies]

View File

@ -23,4 +23,3 @@
## 忐忑
* 本软件的3D封装下载调用了jlc的api不知道哪天就收到了某函所以暂时只在本站开源了在未想办法解决掉该可能引起纠纷的事项之前不想广泛传播所以也请各位道友手下留情不要随意传播本软件
中 东奔西跑黑暗

View File

@ -1,5 +1,5 @@
use iced::{Length, alignment::Horizontal, widget::Column};
use log::info;
use iced::{Length, Task, alignment::Horizontal, widget::Column};
use tracing::info;
use crate::ui::main_window::{MainWindowMsg, TabContent};
@ -14,12 +14,13 @@ pub enum DbBrowserMsg {
impl TabContent for DbBrowser {
type TabMessage = DbBrowserMsg;
fn update(&mut self, msg: Self::TabMessage) {
fn update(&mut self, msg: Self::TabMessage) -> Task<MainWindowMsg> {
match msg {
DbBrowserMsg::Nothing => {
info!("This function not allowed");
}
}
Task::none()
}
fn content(&self) -> iced::Element<'_, MainWindowMsg> {

View File

@ -1,5 +1,5 @@
use iced::{Length, alignment::Horizontal, widget::Column};
use log::info;
use iced::{Length, Task, alignment::Horizontal, widget::Column};
use tracing::info;
#[allow(unused_imports)]
use crate::ui::main_window::{MainWindowMsg, TabContent};
@ -66,7 +66,7 @@ impl TabContent for HomePage {
type TabMessage = HomePageMsg;
fn update(&mut self, msg: Self::TabMessage) {
fn update(&mut self, msg: Self::TabMessage) -> Task<MainWindowMsg> {
match msg {
HomePageMsg::Nothing => {
info!("This way ok.");
@ -96,5 +96,6 @@ impl TabContent for HomePage {
info!("Is the message you should process ? =====>> {msg:?}");
}
}
Task::none()
}
}

View File

@ -1,7 +1,7 @@
use crate::ui::main_window::{MainWindowMsg, TabContent};
use anyhow::Result;
use iced::{Length, alignment::Horizontal, widget::Column};
use log::info;
use iced::{Length, Task, alignment::Horizontal, widget::Column};
use tracing::info;
#[derive(Default)]
pub struct JlcDownloader {
@ -19,7 +19,7 @@ pub enum JlcDownloaderMsg {
impl TabContent for JlcDownloader {
type TabMessage = JlcDownloaderMsg;
fn update(&mut self, msg: Self::TabMessage) {
fn update(&mut self, msg: Self::TabMessage) -> Task<MainWindowMsg> {
match msg {
JlcDownloaderMsg::Nothing => {
info!("JlcDownloaderMsg::Nothing");
@ -34,6 +34,7 @@ impl TabContent for JlcDownloader {
info!("Whach out the msg: {msg:?}");
}
}
Task::none()
}
fn content(&self) -> iced::Element<'_, MainWindowMsg> {
@ -61,6 +62,13 @@ pub struct KeywordSearchItem {
}
impl JlcDownloader {
pub async fn search_keyword(keyword: &str) -> Result<Vec<KeywordSearchItem>> {
if keyword.is_empty() {
tokio::time::sleep(tokio::time::Duration::from_secs(1));
info!("The keyword is empty.");
return Err(anyhow::Error::msg(
"Please insert the keyword before search",
));
}
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
for i in 0..10 {
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
@ -68,6 +76,9 @@ impl JlcDownloader {
}
Ok(Vec::new())
}
pub async fn keyword_search_task() -> Result<Vec<KeywordSearchItem>> {
Ok(Vec::new())
}
pub async fn fetch_item_images(
item: &KeywordSearchItem,
) -> Result<Vec<iced::widget::image::Handle>> {

View File

@ -7,8 +7,8 @@ use crate::ui::part_viewer::PartViewerMsg;
use crate::utils::step_downloader;
use iced::Subscription;
use iced::Task;
use log::info;
use log::warn;
use tracing::info;
use tracing::warn;
#[allow(unused_imports)]
use super::db_browser;
@ -65,7 +65,7 @@ impl MainWindow {
(
Self::default(),
Task::batch([
Task::perform(JlcDownloader::search_keyword("test"), |x| match x {
Task::perform(JlcDownloader::search_keyword(""), |x| match x {
Ok(v) => MainWindowMsg::JlcDownloader(JlcDownloaderMsg::KeywordSearchResult(v)),
Err(e) => MainWindowMsg::JlcDownloader(JlcDownloaderMsg::KeywordSearchError(
format!("{e:?}"),
@ -192,7 +192,7 @@ impl MainWindow {
let btn = button(txt).style(bstyle);
btn.on_press(MainWindowMsg::TabSelected(tab)).into()
}
fn update(&mut self, msg: MainWindowMsg) {
fn update(&mut self, msg: MainWindowMsg) -> Task<MainWindowMsg> {
info!("Process the msg: {msg:?}");
match msg {
MainWindowMsg::ThemeChanged(theme) => {
@ -200,37 +200,35 @@ impl MainWindow {
if let Some(idx) = Theme::ALL.iter().position(|x| x == &theme) {
crate::utils::app_settings::set_curr_theme(idx as u32).unwrap();
}
Task::none()
}
MainWindowMsg::TitleChanged(title) => {
self.title = title;
Task::none()
}
MainWindowMsg::Nothing => {
info!("Nothing");
iced::debug::time("Test".to_owned());
Task::none()
}
MainWindowMsg::TabSelected(i) => {
self.curr_tab = i;
self.curr_tab.save();
Task::none()
}
MainWindowMsg::HomePage(msg) => {
info!("update HomePage");
self.home_page.update(msg);
}
MainWindowMsg::JlcDownloader(msg) => {
self.jlc_downloader.update(msg);
}
MainWindowMsg::DbBrowser(msg) => {
self.db_browser.update(msg);
}
MainWindowMsg::PartViewer(part_viewer_msg) => {
self.part_viewer.update(part_viewer_msg);
}
MainWindowMsg::SearchKeywordChanged(k) => {
self.jlc_downloader
.update(JlcDownloaderMsg::KeywordChanged(k));
self.home_page.update(msg)
}
MainWindowMsg::JlcDownloader(msg) => self.jlc_downloader.update(msg),
MainWindowMsg::DbBrowser(msg) => self.db_browser.update(msg),
MainWindowMsg::PartViewer(part_viewer_msg) => self.part_viewer.update(part_viewer_msg),
MainWindowMsg::SearchKeywordChanged(k) => self
.jlc_downloader
.update(JlcDownloaderMsg::KeywordChanged(k)),
MainWindowMsg::StepDownloader(msg) => {
info!("StepDownloaderEvent: {msg:?}");
Task::none()
}
}
}
@ -254,7 +252,7 @@ impl MainWindow {
pub trait TabContent {
type TabMessage;
fn update(&mut self, msg: Self::TabMessage);
fn update(&mut self, msg: Self::TabMessage) -> Task<MainWindowMsg>;
fn view(&self) -> Element<'_, MainWindowMsg> {
iced::widget::Container::new(self.content())
.width(Length::Fill)

View File

@ -1,5 +1,5 @@
use iced::{Length, alignment::Horizontal, widget::Column};
use log::info;
use iced::{Length, Task, alignment::Horizontal, widget::Column};
use tracing::info;
use crate::ui::main_window::{MainWindowMsg, TabContent};
@ -14,12 +14,13 @@ pub enum PartViewerMsg {
impl TabContent for PartViewer {
type TabMessage = PartViewerMsg;
fn update(&mut self, msg: Self::TabMessage) {
fn update(&mut self, msg: Self::TabMessage) -> Task<MainWindowMsg> {
match msg {
PartViewerMsg::Nothing => {
info!("This function not allowed.");
}
}
Task::none()
}
fn content(&self) -> iced::Element<'_, MainWindowMsg> {