pub mod go;
pub mod python;
pub mod rust;
use crate::parsers::api::{ApiItem, DocComment};
use std::collections::BTreeMap;
#[derive(Debug, Clone, Default)]
pub struct Surface {
pub packages: Vec<Package>,
}
#[derive(Debug, Clone)]
pub struct Package {
pub name: String,
pub lang: crate::models::Language,
pub sep: &'static str,
pub package: String,
pub manifest: String,
pub is_lib: bool,
pub root_file: String,
pub modules: Vec<SurfaceModule>,
}
#[derive(Debug, Clone)]
pub struct SurfaceModule {
pub path: String,
pub name: String,
pub file: String,
pub public: bool,
pub doc: Option<DocComment>,
pub items: Vec<SurfaceItem>,
pub children: Vec<usize>,
pub parent: Option<usize>,
}
#[derive(Debug, Clone)]
pub struct SurfaceItem {
pub item: ApiItem,
pub file: String,
pub public: bool,
pub path: String,
pub defined_at: Option<String>,
pub impl_files: BTreeMap<usize, String>,
}
impl Surface {
pub fn libraries(&self) -> impl Iterator<Item = &Package> {
self.packages.iter().filter(|c| c.is_lib)
}
pub fn extend(&mut self, other: Surface) {
self.packages.extend(other.packages);
}
}
impl Package {
pub fn join(&self, a: &str, b: &str) -> String {
format!("{a}{}{b}", self.sep)
}
pub fn lang_id(&self) -> String {
serde_json::to_value(self.lang)
.ok()
.and_then(|v| v.as_str().map(str::to_string))
.unwrap_or_else(|| "text".into())
}
}