一、绪论
昨天的日志没写,只好给今天的放一块儿了(不是昨天学的知识点太少了)。每次看项目都特别费劲(主要是还没学完rust基础),但是慢慢谷歌(国内关于rust的文章太少了)和查库还没能看懂的,也能小小的应用一下。
二、知识点
1.try_into()方法。try_into()就是将数据转换成等号前面的类型,使用的方法是impl_try_from!里面声明的方法。
pub fn parse_color_indexed(i: &[u8]) -> IResult<&[u8], ColorIndexed> {
let (i, o) = le_u8(i)?;
Ok((i, ColorIndexed(o)))
}
impl_try_from!(ColorIndexed, parse_color_indexed);
pub fn test_color_indexed_in() -> &'static [u8] {
&[24u8]
}
pub fn test_color_indexed_out() -> ColorIndexed {
ColorIndexed(24)
}
#[cfg(test)]
mod tests {
use crate::test_data::{test_color_indexed_in, test_color_indexed_out};
use super::*;
use std::{convert::TryInto, error::Error};
#[test]
fn test_color_indexed() -> Result<(), Box<dyn Error>> {
let color_indexed: ColorIndexed = test_color_indexed_in().try_i