#ergonomically #tries #micro-crate

to_method

A utility micro-crate for using Into more ergonomically

2 stable releases

1.1.0 May 17, 2021
1.0.0 Apr 25, 2021

#560 in Development tools

Download history 15219/week @ 2024-07-27 14104/week @ 2024-08-03 13746/week @ 2024-08-10 15361/week @ 2024-08-17 14400/week @ 2024-08-24 15237/week @ 2024-08-31 14211/week @ 2024-09-07 11376/week @ 2024-09-14 14239/week @ 2024-09-21 13500/week @ 2024-09-28 15731/week @ 2024-10-05 18710/week @ 2024-10-12 17876/week @ 2024-10-19 15577/week @ 2024-10-26 17100/week @ 2024-11-02 13122/week @ 2024-11-09

66,706 downloads per month
Used in 63 crates (4 directly)

CC0 license

6KB

to_method

A utility micro-crate for using Into more ergonomically.

It exposes a To extension trait with a .to() method which you can use to invoke Into::into while specifying the target type and without having to abandon method-call syntax.

Being a micro-crate, it tries to be as nice of a dependency as possible and has:

  • No dependencies of its own
  • No feature flags
  • No build.rs
  • #![no_std]
  • #![forbid(unsafe_code)]

Regular Into usage

let x : u8 = 5;

// The type parameter is on `Into`, not on `Into::into`,
// so we need to do it like this:
let y = Into::<u16>::into(x);

// Depending on context, inference can make this work though:
let z : u32 = y.into();

With To

use to_method::To as _;

let x : u8 = 5;

// The type parameter is on the `to` method, so this works:
let y = x.to::<u16>();

// And you can still rely on inference as well:
let z : u32 = y.to();

No runtime deps