Crates.io | as-what |
lib.rs | as-what |
version | |
source | src |
created_at | 2024-12-11 12:21:27.077629 |
updated_at | 2024-12-11 12:21:27.077629 |
description | Provide a bunch of `as` traits. |
homepage | |
repository | https://github.com/jmjoy/as-what |
max_upload_size | |
id | 1480045 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
as-what
provides a set of custom as
traits to improve type conversions in Rust, enhancing clarity and readability in expressions.
The as
keyword was part of Rust’s early syntax, before the introduction of postfix operators like .await
. Consider the following example using as
:
let index = y as usize * width.get() as usize + x as usize;
In this case, the precedence of the as
keyword is mixed with other operators, making the expression harder to read. Additionally, as
does not support chained operations, limiting its flexibility in complex expressions.
The purpose of this library is to provide custom as
traits that solve these issues, improving the readability of code and allowing more intuitive type conversion expressions. The library helps avoid problems related to operator precedence and enables chaining of operations.
as
traits for type conversion.cargo add as-what
Here is a simple example of how to use the library:
use as_what::AsUsize;
let index = y.as_usize() * width.get().as_usize() + x.as_usize();
If you have any suggestions or find issues, feel free to submit an Issue or Pull Request!
This project is licensed under the MIT License.