Finishing

This commit is contained in:
Chaoscaot
2023-03-08 15:47:51 +01:00
parent 74df144d05
commit 98d797532e
11 changed files with 823 additions and 45 deletions

View File

@@ -0,0 +1,39 @@
use std::path::Path;
#[cfg(feature = "sql")]
use futures::executor::block_on;
use schemsearch_files::Schematic;
#[cfg(feature = "sql")]
use schemsearch_sql::{load_schemdata, SchematicNode};
pub enum SchematicSupplierType<'local> {
PATH(Box<PathSchematicSupplier<'local>>),
#[cfg(feature = "sql")]
SQL(SqlSchematicSupplier),
}
pub struct PathSchematicSupplier<'local> {
pub path: &'local Path,
}
impl PathSchematicSupplier<'_> {
pub fn get_name(&self) -> String {
self.path.file_name().unwrap().to_str().unwrap().to_string()
}
}
#[cfg(feature = "sql")]
pub struct SqlSchematicSupplier {
pub node: SchematicNode,
}
#[cfg(feature = "sql")]
impl SqlSchematicSupplier {
pub fn get_schematic(&self) -> Result<Schematic, String> {
let schemdata = block_on(load_schemdata(self.node.id));
Schematic::load_data(schemdata.as_slice())
}
pub fn get_name(&self) -> String {
format!("{} ({})", self.node.name, self.node.id)
}
}