How to type annotate into call?

I am trying to call foo.into() which is implemented for Into the compiler complains that I need to use type annotations but I have no clue where to put the annotation
I tried

foo.::<String>::into() //seems this is not even valid rust

but I cant get it to work and for some reason this seems to be kept as a secret in the documentation of rust I cant find anywhere where and how to declare type parameters

// edit, not this... <foo as Into<String>>::into()

// UFCS works:

// or put the hint on whatever is receiving the value, like:
let x: String = foo.into();
1 Like

seems that is as well invalid syntax

Oh, sorry, I forgot that's just for pure types. I edited my first reply.

Thanks that seems to be working

I notice you're just feeding this to a format! though -- can you not feed your type into that directly? That is, does your type have Into<String>, but not Display?

Yes I have only implemented Into String for my type

By the way, is there any reason that T: ToString (which is blanket-implemented for T: Display) doesn't imply String: From<T>? Is there any kind of conflict?

It conflicts with T = String case


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.