tool: Support downcasting generic Ec
Removes the `impl Access for &mut dyn Access` I added earlier. But that hasn't proven too useful.
This commit is contained in:
parent
171257916c
commit
2768925ec6
7
tool/Cargo.lock
generated
7
tool/Cargo.lock
generated
@ -42,6 +42,11 @@ dependencies = [
|
||||
"vec_map 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "downcast-rs"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.18"
|
||||
@ -85,6 +90,7 @@ name = "system76_ectool"
|
||||
version = "0.2.3"
|
||||
dependencies = [
|
||||
"clap 2.33.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"downcast-rs 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hidapi 1.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.81 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"redox_hwio 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -133,6 +139,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||
"checksum cc 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)" = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48"
|
||||
"checksum clap 2.33.3 (registry+https://github.com/rust-lang/crates.io-index)" = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
|
||||
"checksum downcast-rs 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
|
||||
"checksum hermit-abi 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c"
|
||||
"checksum hidapi 1.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "76c352a18370f7e7e47bcbfcbdc5432b8c80c705b5d751a25232c659fcf5c775"
|
||||
"checksum libc 0.2.81 (registry+https://github.com/rust-lang/crates.io-index)" = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
|
||||
|
@ -20,10 +20,11 @@ clap = "2"
|
||||
libc = { version = "0.2", optional = true }
|
||||
hidapi = { version = "1.2", default-features = false, features = ["linux-static-hidraw"], optional = true }
|
||||
redox_hwio = { version = "0.1.3", optional = true }
|
||||
downcast-rs = { version = "1.2.0", default-features = false }
|
||||
|
||||
[features]
|
||||
default = ["std", "hidapi"]
|
||||
std = ["libc"]
|
||||
std = ["libc", "downcast-rs/std"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
|
@ -1,4 +1,5 @@
|
||||
use crate::Error;
|
||||
use downcast_rs::Downcast;
|
||||
|
||||
#[cfg(feature = "hidapi")]
|
||||
pub use self::hid::AccessHid;
|
||||
@ -17,7 +18,7 @@ pub use self::lpc::*;
|
||||
mod lpc;
|
||||
|
||||
/// Access method for running an EC command
|
||||
pub trait Access {
|
||||
pub trait Access: Downcast {
|
||||
/// Sends a command using the access method. Only internal use is recommended
|
||||
unsafe fn command(&mut self, cmd: u8, data: &mut [u8]) -> Result<u8, Error>;
|
||||
|
||||
@ -31,16 +32,6 @@ pub trait Access {
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
@ -50,3 +41,5 @@ impl Access for Box<dyn Access> {
|
||||
(**self).data_size()
|
||||
}
|
||||
}
|
||||
|
||||
downcast_rs::impl_downcast!(Access);
|
||||
|
@ -245,14 +245,6 @@ 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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user