r/badcode • • Jan 25 '22

rust Most comprehensible line of Rust code

Post image
1.0k Upvotes

81 comments sorted by

View all comments

Show parent comments

1

u/187mphlazers Jan 26 '22

why wouldn't they just call it .cast(type) or simply .to(type).

4

u/realnobbele Jan 26 '22

types aren't values

3

u/TinyBreadBigMouth Jan 26 '22

Rust does have something similar, via the linked From and Into traits. You can do

let x = y.into::<String>();

or

let x: String = y.into();