0

I'm reading this piece of code:

pub fn ip_addrs<T>(mut self, ip_addrs: T) -> Self
        where T: Into<ManagedSlice<'c, IpCidr>>
    {

T must be of type Into. However, I cannot understand what Into does by reading its definition. Can somebody explain?

Guerlando OCs
  • 1,886
  • 9
  • 61
  • 150

1 Answers1

2

From and Into are two traits specifying protocols for converting between types (without failure). That is if A implements Into<B>, you can always convert an A to a B and it will never fail.

Here it's used such that you can give this function anything which is convertible to a ManagedSlice.

user2722968
  • 13,636
  • 2
  • 46
  • 67
Masklinn
  • 34,759
  • 3
  • 38
  • 57
  • See also: https://stackoverflow.com/questions/29812530/when-should-i-implement-stdconvertfrom-vs-stdconvertinto – E_net4 May 18 '20 at 09:33