MCPcopy Create free account
hub / github.com/TheRedDeveloper/ply-engine / new

Method new

src/storage.rs:18–46  ·  view source on GitHub ↗
(path: &str)

Source from the content-addressed store, hash-verified

16
17impl 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

Callers

nothing calls this directly

Calls 6

normalize_relative_pathFunction · 0.85
platform_app_data_dirFunction · 0.85
join_normalized_pathFunction · 0.85
ply_storage_newFunction · 0.85
wait_for_responseFunction · 0.85
ensure_successFunction · 0.85

Tested by

no test coverage detected