/
githubmirror
/
tauri
Обзор
Документация
Войти
/
githubmirror
/
tauri
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
examples/api/src-tauri/src/cmd.rs
63 строки
1 KB
Tony
fix(api): use array for channel queueing (#12069)
02 янв 2025, 14:19
Не верифицирован
02 янв 2025, 14:19
a16796a
Код
Авторство
О чём код?
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT use serde::{Deserialize, Serialize}; use tauri::{ command, ipc::{Channel, CommandScope}, }; #[derive(Debug, Deserialize)] #[allow(unused)] pub struct RequestBody { id: i32, name: String, } #[derive(Debug, Deserialize)] pub struct LogScope { event: String, } #[command] pub fn log_operation( event: String, payload: Option<String>, command_scope: CommandScope<LogScope>, ) -> Result<(), &'static str> { if command_scope.denies().iter().any(|s| s.event == event) { Err("denied") } else if !command_scope.allows().iter().any(|s| s.event == event) { Err("not allowed") } else { log::info!("{event} {payload:?}"); Ok(()) } } #[derive(Serialize)] pub struct ApiResponse { message: String, } #[command] pub fn perform_request(endpoint: String, body: RequestBody) -> ApiResponse { println!("{endpoint} {body:?}"); ApiResponse { message: "message response".into(), } } #[command] pub fn echo(request: tauri::ipc::Request<'_>) -> tauri::ipc::Response { tauri::ipc::Response::new(request.body().clone()) } #[command] pub fn spam(channel: Channel<i32>) -> tauri::Result<()> { for i in 1..=1_000 { channel.send(i)?; } Ok(()) }