66 lines
1.8 KiB
Rust
66 lines
1.8 KiB
Rust
macro_rules! define_wrapper {
|
|
($name:ident, $type_name:literal, $doc:literal) => {
|
|
#[doc = $doc]
|
|
pub struct $name<'bus> {
|
|
pub(crate) device: crate::Device<'bus>,
|
|
}
|
|
|
|
impl<'bus> $name<'bus> {
|
|
pub const TYPE_NAME: &'static str = $type_name;
|
|
|
|
pub fn attach(bus: &'bus mut crate::DeviceBus) -> crate::Result<Option<Self>> {
|
|
crate::devices::attach_device(bus, Self::TYPE_NAME)
|
|
.map(|opt| opt.map(Self::from_device))
|
|
}
|
|
|
|
pub fn from_device(device: crate::Device<'bus>) -> Self {
|
|
Self { device }
|
|
}
|
|
|
|
pub fn info(&self) -> &crate::DeviceEntry {
|
|
self.device.info()
|
|
}
|
|
|
|
pub fn as_device(&mut self) -> &mut crate::Device<'bus> {
|
|
&mut self.device
|
|
}
|
|
|
|
pub fn into_device(self) -> crate::Device<'bus> {
|
|
self.device
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
pub(crate) use define_wrapper;
|
|
|
|
pub(crate) fn attach_device<'bus>(
|
|
bus: &'bus mut crate::DeviceBus,
|
|
type_name: &str,
|
|
) -> crate::Result<Option<crate::Device<'bus>>> {
|
|
match bus.find(type_name)? {
|
|
Some(entry) => bus.device(&entry.device_id),
|
|
None => Ok(None),
|
|
}
|
|
}
|
|
|
|
pub mod block_operations;
|
|
pub mod cpu;
|
|
pub mod energy_storage;
|
|
pub mod file_import_export;
|
|
pub mod fluid_handler;
|
|
pub mod inventory_operations;
|
|
pub mod item_handler;
|
|
pub mod redstone;
|
|
pub mod sound;
|
|
|
|
pub use block_operations::{BlockOperations, RobotSide};
|
|
pub use cpu::Cpu;
|
|
pub use energy_storage::EnergyStorage;
|
|
pub use file_import_export::{FileImportExport, ImportedFileInfo};
|
|
pub use fluid_handler::FluidHandler;
|
|
pub use inventory_operations::InventoryOperations;
|
|
pub use item_handler::ItemHandler;
|
|
pub use redstone::{ParseSideError, Redstone, Side};
|
|
pub use sound::SoundCard;
|