mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Add minimal robot factory functionality and arc archive support for #6
This commit is contained in:
33
rc_core/src/factory/adapter_enum.rs
Normal file
33
rc_core/src/factory/adapter_enum.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
pub enum Factory {
|
||||
Arc(rc_factory::arc::ArcAdapter),
|
||||
Custom(Box<dyn rc_factory::VehicleFactoryAdapter + Send + Sync + 'static>),
|
||||
None,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl rc_factory::VehicleFactoryAdapter for Factory {
|
||||
async fn vehicle(&self, id: u32) -> Result<Option<rc_factory::VehicleInfo>, Box<dyn std::error::Error>> {
|
||||
match self {
|
||||
Self::Arc(x) => x.vehicle(id).await,
|
||||
Self::Custom(x) => x.vehicle(id).await,
|
||||
Self::None => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
async fn list(&self, query: libfj::robocraft::ListQuery) -> Result<Vec<rc_factory::VehicleQueryInfo>, Box<dyn std::error::Error>> {
|
||||
match self {
|
||||
Self::Arc(x) => x.list(query).await,
|
||||
Self::Custom(x) => x.list(query).await,
|
||||
Self::None => Ok(Vec::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Factory {
|
||||
pub async fn from_config(conf: &crate::persist::FactoryConfig) -> Result<Self, Box<dyn std::error::Error + 'static>> {
|
||||
Ok(match &conf.adapter {
|
||||
crate::persist::AdapterSettings::Arc(x) => Self::Arc(rc_factory::arc::ArcAdapter::init(&x.uri, x.show_expired).await?),
|
||||
crate::persist::AdapterSettings::None => Self::None,
|
||||
})
|
||||
}
|
||||
}
|
||||
2
rc_core/src/factory/mod.rs
Normal file
2
rc_core/src/factory/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
mod adapter_enum;
|
||||
pub use adapter_enum::Factory;
|
||||
Reference in New Issue
Block a user