Crates.io | easy-cast |
lib.rs | easy-cast |
version | |
source | src |
created_at | 2021-03-18 11:05:15.145287 |
updated_at | 2024-12-12 11:17:10.987314 |
description | Type conversions which are expected to succeed |
homepage | |
repository | https://github.com/kas-gui/easy-cast |
max_upload_size | |
id | 370507 |
Cargo.toml error: | TOML parse error at line 19, column 1 | 19 | 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 |
Type conversion, success expected
This library exists to make fallible numeric type conversions easy, without
resorting to the as
keyword.
Conv
is like From
, but supports fallible conversionsCast
is to Conv
what Into
is to From
ConvApprox
] and [CastApprox
] support fallible, approximate conversionConvFloat
and CastFloat
are similar, providing precise control over roundingIf you are wondering "why not just use as
", there are a few reasons:
Why might you not want to use this library?
From
supports a lot more
conversions than Conv
does)!All traits support two methods:
try_*
methods return a Result
and always fail if the correct
conversion is not possibleIn debug builds, methods not returning Result
must panic on failure. As
with the overflow checks on Rust's standard integer arithmetic, this is
considered a tool for finding logic errors. In release builds, these methods
are permitted to return defined but incorrect results similar to the as
keyword.
If the always_assert
feature flag is set, assertions will be turned on in
all builds. Some additional feature flags are available for finer-grained
control (see Cargo.toml
).
Performance is "good enough that it hasn't been a concern".
In debug builds and when always_assert
is enabled, the priority is testing
but overhead should be small.
In release builds without always_assert
, conv*
methods should reduce to
x as T
(with necessary additions for rounding).
When the crate's default features are disabled (and std
is not enabled)
then the library supports no_std
. In this case, ConvFloat
and
CastFloat
are only available if the libm
optional dependency is
enabled.
The Minumum Supported Rust Version is 1.53.0 (IntoIterator for [T; N]
).
By default, std
support is required. With default features disabled no_std
is supported, but the ConvFloat
and CastFloat
traits are unavailable.
Enabling the libm
feature will re-enable these traits.
The COPYRIGHT file includes a list of contributors who claim copyright on this project. This list may be incomplete; new contributors may optionally add themselves to this list.
The easy-cast library is published under the terms of the Apache License, Version 2.0. You may obtain a copy of this licence from the LICENSE file or on the following webpage: https://www.apache.org/licenses/LICENSE-2.0