tenho seguinte código tauri v2 rust use serde::{Deserialize, Serialize}; use…
- User
tenho seguinte código tauri v2 rust
use serde::{Deserialize, Serialize}; use std::path::{Path, PathBuf}; use tauri::{AppHandle, Emitter}; use reqwest::Client; use tokio::fs; use tokio::io::AsyncWriteExt; use std::time::{Duration, Instant};
#[derive(Deserialize, Clone)] struct PatchEntry { file_name: String, }
#[derive(Serialize, Clone)] struct DownloadInfo { current_file: usize, total_files: usize, file_name: String, downloaded_bytes: u64, total_bytes: u64, }
#[derive(Serialize, Clone)] struct DownloadStatus { status: String, additional_info: Option, }
async fn get_exe_dir() -> Result<PathBuf, std::io::Error> { tokio::task::spawn_blocking(|| { std::env::current_exe()?.parent() .map(|p| p.to_path_buf()) .ok_or_else(|| std::io::Error::new( std::io::ErrorKind::Other, "Não foi possível determinar o diretório do executável", )) }).await? }
async fn dir_exists(path: &Path) -> Result<bool, std::io::Error> { match fs::metadata(path).await { Ok(metadata) => Ok(metadata.is_dir()), Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(false), Err(err) => Err(err), } }
async fn read_patch_file(path: &Path) -> Result<Vec, String> { let content = fs::read_to_string(path).await.map_err(|e| e.to_string())?; let patches: Vec = serde_json::from_str(&content).map_err(|e| e.to_string())?; Ok(patches) }
async fn emit_download_status( app_handle: &AppHandle, status: &str, additional_info: Option, ) -> Result<(), String> { app_handle.emit("download_status", DownloadStatus { status: status.to_string(), additional_info, }).map_err(|e| e.to_string()) }
async fn download_file( app_handle: &AppHandle, client: &Client, entry: &PatchEntry, download_dir: &Path, current_file: usize, total_files: usize, ) -> Result<(), String> { let url = format!("https://hil-speed.hetzner.com/{}", entry.file_name); let file_path = download_dir.join(&entry.file_name);
code - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.