tool: Support for owned and unowned generic Ec
This commit is contained in:
parent
f4458aebca
commit
0c1584385c
@ -24,3 +24,23 @@ pub trait Access {
|
||||
/// The maximum size that can be provided for the data argument
|
||||
fn data_size(&self) -> usize;
|
||||
}
|
||||
|
||||
impl Access for &mut dyn Access {
|
||||
unsafe fn command(&mut self, cmd: u8, data: &mut [u8]) -> Result<u8, Error> {
|
||||
(**self).command(cmd, data)
|
||||
}
|
||||
|
||||
fn data_size(&self) -> usize {
|
||||
(**self).data_size()
|
||||
}
|
||||
}
|
||||
|
||||
impl Access for Box<dyn Access> {
|
||||
unsafe fn command(&mut self, cmd: u8, data: &mut [u8]) -> Result<u8, Error> {
|
||||
(**self).command(cmd, data)
|
||||
}
|
||||
|
||||
fn data_size(&self) -> usize {
|
||||
(**self).data_size()
|
||||
}
|
||||
}
|
||||
|
@ -244,6 +244,23 @@ impl<A: Access> Ec<A> {
|
||||
];
|
||||
self.command(Cmd::LedSetColor, &mut data)
|
||||
}
|
||||
|
||||
pub fn as_dyn(&mut self) -> Ec<&mut dyn Access> {
|
||||
Ec {
|
||||
access: &mut self.access,
|
||||
version: self.version,
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_dyn(self) -> Ec<Box<dyn Access>>
|
||||
where A: 'static {
|
||||
Ec {
|
||||
access: Box::new(self.access),
|
||||
version: self.version,
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EcSpi<'a, A: Access> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user