virtio: video: Add an Error implementation for TryFromFormatError.

As a convention, error types should always implement Error, so we're
doing it here.

The traits are manually implemented as opposed to using ThisError; it
was simple enough, and using ThisError requires making the error type an
enum which makes it more verbose to construct.

BUG=None
TEST=cargo build --features "video-decoder,ffmpeg"

Change-Id: If94926c1b2f14295b29c877c2c70d361b4adee90
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3925332
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
This commit is contained in:
Tatsuyuki Ishi 2022-09-30 14:23:30 +09:00 committed by crosvm LUCI
parent 03fdffb447
commit 244033437e

View file

@ -3,6 +3,7 @@
// found in the LICENSE file.
use std::error::Error;
use std::fmt::{Display, Formatter};
use thiserror::Error as ThisError;
@ -131,6 +132,17 @@ impl TryAsAvFrameExt for GuestResource {
#[derive(Debug)]
pub struct TryFromFormatError(());
impl Display for TryFromFormatError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"No matching format to convert between AvPixelFormat and Format"
)
}
}
impl Error for TryFromFormatError {}
impl TryFrom<Format> for AvPixelFormat {
type Error = TryFromFormatError;