Skip to content

solution for error in Windows: non-exhaustive patterns  #154

@altunenes

Description

@altunenes

TL/DR: #155

First of all, thank you for this beautiful contribution. ❤️

I wanted to use rust-ffmpeg in one of my projects and it compiles on MAC without any problem. But when I try it on Windows 11 I get an error: 😢

error[E0004]: non-exhaustive patterns: sys::AVPixelFormat::AV_PIX_FMT_P212BE, sys::AVPixelFormat::AV_PIX_FMT_P212LE, sys::AVPixelFormat::AV_PIX_FMT_P412BE and 1 more not covered

error[E0004]: non-exhaustive patterns: sys::AVCodecID::AV_CODEC_ID_PDV sys::AVCodecID::AV_CODEC_ID_EVC, sys::AVCodecID::AV_CODEC_ID_RTV1 and 3 more not covered

I made the following implementations and my problem was solved: 🥳

src/util/format/pixel.rs

pub enum Pixel {

I updated the Pixel enum to include all possible pixel formats like so:

#[derive(Eq, PartialEq, Copy, Clone, Debug)]
pub enum Pixel {
    None,
    P212BE,
    P212LE,
    P412BE,
    P412LE,
    //others...
}

Then, I updated the implementation of From for Pixel and From for AVPixelFormat to include these new enumerations.

impl From<AVPixelFormat> for Pixel {
    #[inline]
    fn from(value: AVPixelFormat) -> Self {
        match value {
            AV_PIX_FMT_NONE => Pixel::None,
            AV_PIX_FMT_P212BE => Pixel::P212BE,
            AV_PIX_FMT_P212LE => Pixel::P212LE,
            AV_PIX_FMT_P412BE => Pixel::P412BE,
            AV_PIX_FMT_P412LE => Pixel::P412LE,
            //others...
        }
    }
}
impl From<Pixel> for AVPixelFormat {
    #[inline]
    fn from(value: Pixel) -> AVPixelFormat {
        match value {
            Pixel::None => AV_PIX_FMT_NONE,
            Pixel::P212BE => AV_PIX_FMT_P212BE,
            Pixel::P212LE => AV_PIX_FMT_P212LE,
            Pixel::P412BE => AV_PIX_FMT_P412BE,
            Pixel::P412LE => AV_PIX_FMT_P412LE,
            //others...
        }
    }
}

In the id.rs file, I updated the Id enum and did a similar update for the From for Id and From for AVCodecID implementations:
src/codec/id.rs

pub enum Id {

#[allow(non_camel_case_types)]
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
pub enum Id {
    None,
    PDV,
    EVC,
    RTV1,

    VMIX,
    AC4,
    SMPTE2038,
    //others...
}

impl From<AVCodecID> for Id {
    fn from(value: AVCodecID) -> Self {
        match value {
            AV_CODEC_ID_NONE => Id::None,
            AV_CODEC_ID_PDV => Id::PDV,
            AV_CODEC_ID_EVC => Id::EVC,
            AV_CODEC_ID_RTV1 => Id::RTV1,

            AV_CODEC_ID_VMIX => Id::VMIX,
            AV_CODEC_ID_AC4 => Id::AC4,
            AV_CODEC_ID_SMPTE_2038 => Id::SMPTE2038,
            //others...
        }
    }
}

impl From<Id> for AVCodecID {
    fn from(value: Id) -> AVCodecID {
        match value {
            Id::None => AV_CODEC_ID_NONE,
            Id::PDV => AV_CODEC_ID_PDV,
            Id::EVC => AV_CODEC_ID_EVC,
            Id::RTV1 => AV_CODEC_ID_RTV1,

            Id::VMIX => AV_CODEC_ID_VMIX,
            Id::AC4 => AV_CODEC_ID_AC4,
            Id::SMPTE2038 => AV_CODEC_ID_SMPTE_2038,
            //others...
        }
    }
}

after these implementations, all is okay now
happy coding. 😸

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions