(path: &str)
| 16 | |
| 17 | impl Storage { |
| 18 | pub async fn new(path: &str) -> Result<Self, String> { |
| 19 | #[cfg(not(target_arch = "wasm32"))] |
| 20 | { |
| 21 | let candidate = PathBuf::from(path); |
| 22 | let root_path = if candidate.is_absolute() { |
| 23 | candidate |
| 24 | } else { |
| 25 | let normalized_root = normalize_relative_path(path, "Storage::new path")?; |
| 26 | let app_data_dir = platform_app_data_dir()?; |
| 27 | join_normalized_path(&app_data_dir, &normalized_root) |
| 28 | }; |
| 29 | |
| 30 | std::fs::create_dir_all(&root_path).map_err(|e| e.to_string())?; |
| 31 | |
| 32 | Ok(Self { root_path }) |
| 33 | } |
| 34 | |
| 35 | #[cfg(target_arch = "wasm32")] |
| 36 | { |
| 37 | let normalized_root = normalize_relative_path(path, "Storage::new path")?; |
| 38 | let op_id = unsafe { ply_storage_new(JsObject::string(&normalized_root)) }; |
| 39 | let result = wait_for_response(op_id).await?; |
| 40 | ensure_success(&result)?; |
| 41 | |
| 42 | Ok(Self { |
| 43 | root_id: result.field_u32("storage_id") as i32, |
| 44 | }) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | pub async fn save_string(&self, path: &str, data: &str) -> Result<(), String> { |
| 49 | self.save_bytes(path, data.as_bytes()).await |
nothing calls this directly
no test coverage detected