as-what

Crates.ioas-what
lib.rsas-what
version
sourcesrc
created_at2024-12-11 12:21:27.077629
updated_at2024-12-11 12:21:27.077629
descriptionProvide a bunch of `as` traits.
homepage
repositoryhttps://github.com/jmjoy/as-what
max_upload_size
id1480045
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`
size0
jmjoy (jmjoy)

documentation

README

as-what

as-what provides a set of custom as traits to improve type conversions in Rust, enhancing clarity and readability in expressions.

Background

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.

Purpose

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.

Features

  • Provides various as traits for type conversion.
  • Improves expression readability by addressing operator precedence issues.
  • Supports chaining of operations for more flexible and concise code.

Installation

cargo add as-what

Example Usage

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();

Contributing

If you have any suggestions or find issues, feel free to submit an Issue or Pull Request!

License

This project is licensed under the MIT License.

Commit count: 4

cargo fmt