The function is expected to accept a command which can be converted to a string, and also I am using anyhow to handle the error thing. Here is the code:
pub fn converter<T: TryInto<String>>(input: T) -> Result<String>
where
T::Error: Into<anyhow::Error>,
{
// error here
// the trait bound `<T as TryInto<std::string::String>>::Error: StdError` is not satisfied
// required because of the requirements on the impl of `From<<T as TryInto<std::string::String>>::Error>` for `anyhow::Error`
// required because of the requirements on the impl of `FromResidual<Result<Infallible, <T as TryInto<std::string::String>>::Error>>` for `Result<std::string::String, anyhow::Error>
let out_str = input.try_into()?;
Ok(out_str)
}
I have added a type restriction for T::Error as T::Error: Into<anyhow::Error>, hope the compiler can do the error handling, but shows the T::Error can't be convert to a anyhow::Error.
The type restriction is referred from: https://github.com/dtolnay/anyhow/issues/172, but I still can't figure out how to use the TryInto generic with anyhow.