mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-10 20:19:07 +00:00
Add TryFrom implementation for PciClassCode
This is useful for example when parsing numeric PCI class code values from the command line. BUG=b:167947780 TEST=None Change-Id: I55515af2fa7e38bc26f4c2eebb083f1e45aebf22 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3245496 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Mattias Nissler <mnissler@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
parent
441a68194a
commit
fce74e6fc2
1 changed files with 22 additions and 1 deletions
|
@ -2,6 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use std::convert::TryFrom;
|
||||
use std::convert::TryInto;
|
||||
|
||||
use base::warn;
|
||||
|
@ -44,7 +45,7 @@ pub enum PciHeaderType {
|
|||
|
||||
/// Classes of PCI nodes.
|
||||
#[allow(dead_code)]
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Copy, Clone, enumn::N)]
|
||||
pub enum PciClassCode {
|
||||
TooOld,
|
||||
MassStorage,
|
||||
|
@ -61,8 +62,11 @@ pub enum PciClassCode {
|
|||
SerialBusController,
|
||||
WirelessController,
|
||||
IntelligentIoController,
|
||||
SatelliteCommunicationController,
|
||||
EncryptionController,
|
||||
DataAcquisitionSignalProcessing,
|
||||
ProcessingAccelerator,
|
||||
NonEssentialInstrumentation,
|
||||
Other = 0xff,
|
||||
}
|
||||
|
||||
|
@ -72,6 +76,23 @@ impl PciClassCode {
|
|||
}
|
||||
}
|
||||
|
||||
#[sorted]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum PciClassCodeParseError {
|
||||
#[error("Unknown class code")]
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl TryFrom<u8> for PciClassCode {
|
||||
type Error = PciClassCodeParseError;
|
||||
fn try_from(v: u8) -> std::result::Result<PciClassCode, PciClassCodeParseError> {
|
||||
match PciClassCode::n(v) {
|
||||
Some(class) => Ok(class),
|
||||
None => Err(PciClassCodeParseError::Unknown),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A PCI sublcass. Each class in `PciClassCode` can specify a unique set of subclasses. This trait
|
||||
/// is implemented by each subclass. It allows use of a trait object to generate configurations.
|
||||
pub trait PciSubclass {
|
||||
|
|
Loading…
Reference in a new issue