Skip to main content

tauri_plugin_ios_bookmark/
models.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
4#[serde(rename_all = "camelCase")]
5pub struct PickBookmarkRequest {
6    #[serde(skip_serializing_if = "Option::is_none")]
7    pub target_path: Option<String>,
8    #[serde(skip_serializing_if = "Option::is_none")]
9    pub suggested_file_name: Option<String>,
10}
11
12#[derive(Debug, Clone, Serialize, Deserialize)]
13#[serde(rename_all = "camelCase")]
14pub struct PickFolderBookmarkRequest {
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub target_path: Option<String>,
17}
18
19/// Returned when the user picks a file and a bookmark is created.
20#[derive(Debug, Clone, Serialize, Deserialize)]
21#[serde(rename_all = "camelCase")]
22pub struct PickResult {
23    /// Opaque bookmark identifier (UUID string).
24    pub bookmark_id: String,
25    /// Display filename (e.g. "notes.md").
26    pub file_name: String,
27    /// Original file path for display in recent/resume UI.
28    pub file_path: String,
29    /// Full UTF-8 content of the file.
30    pub content: String,
31}
32
33/// Returned when the user picks a folder and a bookmark is created.
34#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(rename_all = "camelCase")]
36pub struct PickFolderResult {
37    /// Opaque bookmark identifier (UUID string).
38    pub bookmark_id: String,
39    /// Display folder name (e.g. "Docs").
40    pub folder_name: String,
41    /// Original folder path for display and matching.
42    pub folder_path: String,
43}
44
45/// Returned when resolving a bookmark and reading its content.
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(rename_all = "camelCase")]
48pub struct ReadResult {
49    pub file_name: String,
50    pub file_path: String,
51    pub content: String,
52}
53
54#[derive(Debug, thiserror::Error)]
55pub enum BookmarkError {
56    #[error("security-scoped bookmarks are not supported on this platform")]
57    Unsupported,
58    #[error("bookmark not found: {0}")]
59    NotFound(String),
60    #[error("bookmark is stale — user must re-pick the file")]
61    Stale,
62    #[error("access denied")]
63    PermissionDenied,
64    #[error("I/O error: {0}")]
65    Io(String),
66    #[error("cancelled")]
67    Cancelled,
68    #[error("selected file does not match requested target")]
69    TargetMismatch,
70    #[error("native error: {0}")]
71    Native(String),
72}
73
74impl serde::Serialize for BookmarkError {
75    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
76        s.serialize_str(&self.to_string())
77    }
78}