pub fn cpu_identifier(
        res: CpuidResult,
        required_vendor: Option<Vendor>,
    ) -> (bool, Option<String>) {
        let vendor = Vendor::get();
        let supported_cpu =
            required_vendor.is_none() || required_vendor.as_ref() == vendor.as_ref().ok();
        let identifier_fmt = |name: Option<&str>| {
            format!(
                "{} | {}",
                name.unwrap_or("[unknown model]"),
                vendor
                    .map(|v| v.id().to_string())
                    .unwrap_or_else(|e| format!("[{}]", e))
            )
        };

        if res.eax < 0x80000004 {
            // The processor brand string (model) is unavailable.
            return (supported_cpu, Some(identifier_fmt(None)));
        }

        // https://en.wikipedia.org/wiki/CPUID#EAX=80000002h,80000003h,80000004h:_Processor_Brand_String
        const LEAVES: [u32; 3] = [0x80000002, 0x80000003, 0x80000004];
        const CHUNK_SIZE: usize = size_of::<u32>() * 4;
        const MODEL_LEN: usize = LEAVES.len() * CHUNK_SIZE;
        const_assert_eq!(MODEL_LEN, 48);
        let mut model: [u8; MODEL_LEN] = [0; MODEL_LEN];

        // Copy the string in 3 parts over several calls.
        for (i, leaf) in LEAVES.into_iter().enumerate() {
            // Get the next part of the model name.
            let res = unsafe { __cpuid(leaf) };
            let string_part = [
                res.eax.to_le_bytes(),
                res.ebx.to_le_bytes(),
                res.ecx.to_le_bytes(),
                res.edx.to_le_bytes(),
            ]
            .concat();
            // Copy all 4 registers into the model name.
            let start = i * CHUNK_SIZE;
            let destination = &mut model[start..start + CHUNK_SIZE];
            destination.clone_from_slice(&string_part);
        }

        let model_name = String::from_utf8_lossy(model.as_slice());
        (
            supported_cpu,
            Some(identifier_fmt(Some(model_name.trim_matches(char::from(0))))),
        )
    }
/// Get the Processor Brand String or the CPU manufacturer if unavailable.
Get the Processor Brand String or the CPU manufacturer if unavailable.
Get the Processor Brand String or the CPU manufacturer if unavailable .
pub fn cpu_identifier(
        res: CpuidResult,
        required_vendor: Option<Vendor>,
    ) -> (bool, Option<String>) {
        let vendor = Vendor::get();
        let supported_cpu =
            required_vendor.is_none() || required_vendor.as_ref() == vendor.as_ref().ok();
        let identifier_fmt = |name: Option<&str>| {
            format!(
                "{} | {}",
                name.unwrap_or("[unknown model]"),
                vendor
                    .map(|v| v.id().to_string())
                    .unwrap_or_else(|e| format!("[{}]", e))
            )
        };
        if res.eax < 0x80000004 {
            // The processor brand string (model) is unavailable.
            return (supported_cpu, Some(identifier_fmt(None)));
        }
        // https://en.wikipedia.org/wiki/CPUID#EAX=80000002h,80000003h,80000004h:_Processor_Brand_String
        const LEAVES: [u32; 3] = [0x80000002, 0x80000003, 0x80000004];
        const CHUNK_SIZE: usize = size_of::<u32>() * 4;
        const MODEL_LEN: usize = LEAVES.len() * CHUNK_SIZE;
        const_assert_eq!(MODEL_LEN, 48);
        let mut model: [u8; MODEL_LEN] = [0; MODEL_LEN];
        // Copy the string in 3 parts over several calls.
        for (i, leaf) in LEAVES.into_iter().enumerate() {
            // Get the next part of the model name.
            let res = unsafe { __cpuid(leaf) };
            let string_part = [
                res.eax.to_le_bytes(),
                res.ebx.to_le_bytes(),
                res.ecx.to_le_bytes(),
                res.edx.to_le_bytes(),
            ]
            .concat();
            // Copy all 4 registers into the model name.
            let start = i * CHUNK_SIZE;
            let destination = &mut model[start..start + CHUNK_SIZE];
            destination.clone_from_slice(&string_part);
        }
        let model_name = String::from_utf8_lossy(model.as_slice());
        (
            supported_cpu,
            Some(identifier_fmt(Some(model_name.trim_matches(char::from(0))))),
        )
    }
pub fn cpu_identifier ( res : CpuidResult , required_vendor : Option < Vendor > , ) -> ( bool , Option < String > ) { let vendor = Vendor :: get ( ) ; let supported_cpu = required_vendor . is_none ( ) || required_vendor . as_ref ( ) == vendor . as_ref ( ) . ok ( ) ; let identifier_fmt = | name : Option < & str > | { format ! ( " " name unwrap_or ( " " ) vendor map ( v v id ( ) to_string ( ) ) unwrap_or_else ( e format ( " " e ) ) ) } ; if res . eax < 0x80000004 { // The processor brand string (model) is unavailable. return ( supported_cpu , Some ( identifier_fmt ( None ) ) ) ; } // https://en.wikipedia.org/wiki/CPUID#EAX=80000002h,80000003h,80000004h:_Processor_Brand_String const LEAVES : [ u32 ; 3 ] = [ 0x80000002 , 0x80000003 , 0x80000004 ] ; const CHUNK_SIZE : usize = size_of :: < u32 > ( ) * 4 ; const MODEL_LEN : usize = LEAVES . len ( ) * CHUNK_SIZE ; const_assert_eq ! ( MODEL_LEN 48 ) ; let mut model : [ u8 ; MODEL_LEN ] = [ 0 ; MODEL_LEN ] ; // Copy the string in 3 parts over several calls. for ( i , leaf ) in LEAVES . into_iter ( ) . enumerate ( ) { // Get the next part of the model name. let res = unsafe { __cpuid ( leaf ) } ; let string_part = [ res . eax . to_le_bytes ( ) , res . ebx . to_le_bytes ( ) , res . ecx . to_le_bytes ( ) , res . edx . to_le_bytes ( ) , ] . concat ( ) ; // Copy all 4 registers into the model name. let start = i * CHUNK_SIZE ; let destination = & mut model [ start .. start + CHUNK_SIZE ] ; destination . clone_from_slice ( & string_part ) ; } let model_name = String :: from_utf8_lossy ( model . as_slice ( ) ) ; ( supported_cpu , Some ( identifier_fmt ( Some ( model_name . trim_matches ( char :: from ( 0 ) ) ) ) ) , ) }
Get the Processor Brand String or the CPU manufacturer if unavailable.
Get the Processor Brand String or the CPU manufacturer if unavailable .
res
CpuidResult
required_vendor
Option<Vendor>
res
CpuidResult
required_vendor
Option<Vendor>