该函数应该接受一个可以转换为字符串的命令,并且我正在使用任何方法来处理错误.
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)
}
我已经将T::Error
作为T::Error: Into<anyhow::Error>
添加了一个类型限制,希望编译器可以进行错误处理,但显示T::Error
不能转换为anyhow::Error
.
类型限制引用自:https://github.com/dtolnay/anyhow/issues/172,但我仍然不知道如何将TryInto
泛型与一起使用.