fn from_json_str(json: &str) -> Result<SystemPowerModeConfig, Error> {
        #[derive(Deserialize)]
        struct SystemPowerModeConfigDe {
            clients: HashMap<String, ClientConfigDe>,
        }

        #[derive(Deserialize)]
        struct ClientConfigDe {
            mode_matches: Vec<ModeMatchDe>,
            default_level: u64,
        }

        #[derive(Deserialize)]
        struct ModeMatchDe {
            mode: String,
            power_level: u64,
        }

        impl TryInto<SystemPowerModeConfig> for SystemPowerModeConfigDe {
            type Error = anyhow::Error;
            fn try_into(self) -> Result<SystemPowerModeConfig, Self::Error> {
                let mut clients = HashMap::new();
                for (k, v) in self.clients.into_iter() {
                    clients.insert(str_to_client_type(&k)?, v.try_into()?);
                }
                Ok(SystemPowerModeConfig { clients })
            }
        }

        impl TryInto<ClientConfig> for ClientConfigDe {
            type Error = Error;
            fn try_into(self) -> Result<ClientConfig, Self::Error> {
                let mode_matches = self
                    .mode_matches
                    .into_iter()
                    .map(|m| m.try_into())
                    .collect::<Result<Vec<_>, _>>()?;
                Ok(ClientConfig { mode_matches, default_level: self.default_level })
            }
        }

        impl TryInto<ModeMatch> for ModeMatchDe {
            type Error = Error;
            fn try_into(self) -> Result<ModeMatch, Self::Error> {
                Ok(ModeMatch {
                    mode: str_to_system_mode(&self.mode)?,
                    power_level: self.power_level,
                })
            }
        }

        let deserializer: SystemPowerModeConfigDe = serde_json5::from_str(json)?;
        deserializer.try_into()
    }
/// Attempts to create a `SystemPowerModeConfig` instance from a JSON5 string.
///
/// The function eases deserialization by using locally defined structs consisting only of types
/// that are naturally supported by Serde's deserialization system (these local types end in
/// "De"). If deserialization of these structs succeeds, then they are converted to the desired
/// `SystemPowerModeConfig` struct with the help of `TryInto` impls and helper functions.
Attempts to create a `SystemPowerModeConfig` instance from a JSON5 string.
The function eases deserialization by using locally defined structs consisting only of types
that are naturally supported by Serde's deserialization system (these local types end in
"De"). If deserialization of these structs succeeds, then they are converted to the desired
`SystemPowerModeConfig` struct with the help of `TryInto` impls and helper functions.
Attempts to create a ` SystemPowerModeConfig ` instance from a JSON5 string . The function eases deserialization by using locally defined structs consisting only of types that are naturally supported by Serde ' s deserialization system ( these local types end in " De " ) . If deserialization of these structs succeeds then they are converted to the desired ` SystemPowerModeConfig ` struct with the help of ` TryInto ` impls and helper functions .
fn from_json_str(json: &str) -> Result<SystemPowerModeConfig, Error> {
        #[derive(Deserialize)]
        struct SystemPowerModeConfigDe {
            clients: HashMap<String, ClientConfigDe>,
        }
        #[derive(Deserialize)]
        struct ClientConfigDe {
            mode_matches: Vec<ModeMatchDe>,
            default_level: u64,
        }
        #[derive(Deserialize)]
        struct ModeMatchDe {
            mode: String,
            power_level: u64,
        }
        impl TryInto<SystemPowerModeConfig> for SystemPowerModeConfigDe {
            type Error = anyhow::Error;
            fn try_into(self) -> Result<SystemPowerModeConfig, Self::Error> {
                let mut clients = HashMap::new();
                for (k, v) in self.clients.into_iter() {
                    clients.insert(str_to_client_type(&k)?, v.try_into()?);
                }
                Ok(SystemPowerModeConfig { clients })
            }
        }
        impl TryInto<ClientConfig> for ClientConfigDe {
            type Error = Error;
            fn try_into(self) -> Result<ClientConfig, Self::Error> {
                let mode_matches = self
                    .mode_matches
                    .into_iter()
                    .map(|m| m.try_into())
                    .collect::<Result<Vec<_>, _>>()?;
                Ok(ClientConfig { mode_matches, default_level: self.default_level })
            }
        }
        impl TryInto<ModeMatch> for ModeMatchDe {
            type Error = Error;
            fn try_into(self) -> Result<ModeMatch, Self::Error> {
                Ok(ModeMatch {
                    mode: str_to_system_mode(&self.mode)?,
                    power_level: self.power_level,
                })
            }
        }
        let deserializer: SystemPowerModeConfigDe = serde_json5::from_str(json)?;
        deserializer.try_into()
    }
fn from_json_str ( json : & str ) -> Result < SystemPowerModeConfig , Error > { # [ derive ( Deserialize ) ] struct SystemPowerModeConfigDe { clients : HashMap < String , ClientConfigDe > , } # [ derive ( Deserialize ) ] struct ClientConfigDe { mode_matches : Vec < ModeMatchDe > , default_level : u64 , } # [ derive ( Deserialize ) ] struct ModeMatchDe { mode : String , power_level : u64 , } impl TryInto < SystemPowerModeConfig > for SystemPowerModeConfigDe { type Error = anyhow :: Error ; fn try_into ( self ) -> Result < SystemPowerModeConfig , Self :: Error > { let mut clients = HashMap :: new ( ) ; for ( k , v ) in self . clients . into_iter ( ) { clients . insert ( str_to_client_type ( & k ) ? , v . try_into ( ) ? ) ; } Ok ( SystemPowerModeConfig { clients } ) } } impl TryInto < ClientConfig > for ClientConfigDe { type Error = Error ; fn try_into ( self ) -> Result < ClientConfig , Self :: Error > { let mode_matches = self . mode_matches . into_iter ( ) . map ( | m | m . try_into ( ) ) . collect :: < Result < Vec < _ > , _ > > ( ) ? ; Ok ( ClientConfig { mode_matches , default_level : self . default_level } ) } } impl TryInto < ModeMatch > for ModeMatchDe { type Error = Error ; fn try_into ( self ) -> Result < ModeMatch , Self :: Error > { Ok ( ModeMatch { mode : str_to_system_mode ( & self . mode ) ? , power_level : self . power_level , } ) } } let deserializer : SystemPowerModeConfigDe = serde_json5 :: from_str ( json ) ? ; deserializer . try_into ( ) }
Attempts to create a `SystemPowerModeConfig` instance from a JSON5 string.
Attempts to create a ` SystemPowerModeConfig ` instance from a JSON5 string .
json
&str
json
&str