From fb0721770146ce39244f5bc4021a93083d746d25 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 20 Sep 2020 18:23:53 +0300 Subject: [PATCH] Add TryFrom trait for u32 -> PixelFormat --- src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 21e3433..fbab0a9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,7 @@ #![no_std] +use core::convert::TryFrom; + const CMDLINE_SIZE: usize = 256; pub trait LoadProtocol: Sized { @@ -73,3 +75,15 @@ pub struct ProtoV1 { pub cmdline: [u8; CMDLINE_SIZE] } + +impl TryFrom for PixelFormat { + type Error = (); + + fn try_from(f: u32) -> Result { + match f { + 0 => Ok(PixelFormat::LfbRgb32), + 1 => Ok(PixelFormat::LfbBgr32), + _ => Err(()) + } + } +}