Download packages/tauri/examples/api/src-tauri/src/cmd.rs from echodict/readest: direct link, hf CLI and curl.
- Browser
- Download file 1.33 kB
-
https://huggingface.co/datasets/echodict/readest/resolve/main/packages/tauri/examples/api/src-tauri/src/cmd.rs
- Command line
-
hf download hf://datasets/echodict/readest/packages/tauri/examples/api/src-tauri/src/cmd.rs
-
curl -L -o cmd.rs https://huggingface.co/datasets/echodict/readest/resolve/main/packages/tauri/examples/api/src-tauri/src/cmd.rs
1.33 kB
| // 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}, | |
| }; | |
| pub struct RequestBody { | |
| id: i32, | |
| name: String, | |
| } | |
| pub struct LogScope { | |
| event: String, | |
| } | |
| 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(()) | |
| } | |
| } | |
| pub struct ApiResponse { | |
| message: String, | |
| } | |
| pub fn perform_request(endpoint: String, body: RequestBody) -> ApiResponse { | |
| println!("{endpoint} {body:?}"); | |
| ApiResponse { | |
| message: "message response".into(), | |
| } | |
| } | |
| pub fn echo(request: tauri::ipc::Request<'_>) -> tauri::ipc::Response { | |
| tauri::ipc::Response::new(request.body().clone()) | |
| } | |
| pub fn spam(channel: Channel<i32>) -> tauri::Result<()> { | |
| for i in 1..=1_000 { | |
| channel.send(i)?; | |
| } | |
| Ok(()) | |
| } | |