#ergonomically #flags #tries #micro-crate #forbid

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

#580 in Algorithms

Download history 10731/week @ 2024-01-09 11970/week @ 2024-01-16 13137/week @ 2024-01-23 11823/week @ 2024-01-30 12580/week @ 2024-02-06 14237/week @ 2024-02-13 13911/week @ 2024-02-20 14617/week @ 2024-02-27 15450/week @ 2024-03-05 17544/week @ 2024-03-12 18181/week @ 2024-03-19 15688/week @ 2024-03-26 16557/week @ 2024-04-02 15983/week @ 2024-04-09 18999/week @ 2024-04-16 21207/week @ 2024-04-23

74,923 downloads per month
Used in 47 crates (2 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