//! Cloud source integration seam. The host installs a provider when one exists; //! the default workspace stays disconnected and never fabricates or stores files. use anyhow::Result; #[derive(Clone, Debug)] pub struct SourceFile { pub id: String, pub path: String, } #[derive(Clone, Debug)] pub struct OpenedSource { pub path: String, pub code: String, } pub trait CloudSourceProvider: std::fmt::Debug + Send { fn list_files(&mut self) -> Result>; fn open_file(&mut self, id: &str) -> Result; } #[derive(Debug, Default)] pub struct SourceWorkspace { pub provider: Option>, pub files: Vec, pub opened: Option, pub error: String, } impl SourceWorkspace { pub fn refresh(&mut self) { let Some(provider) = &mut self.provider else { self.error = "No cloud file provider configured".into(); return; }; match provider.list_files() { Ok(files) => { self.files = files; self.error.clear(); } Err(error) => self.error = error.to_string(), } } pub fn open(&mut self, id: &str) { let Some(provider) = &mut self.provider else { return; }; match provider.open_file(id) { Ok(source) => { self.opened = Some(source); self.error.clear(); } Err(error) => self.error = error.to_string(), } } }