Crate positive

Crate positive 

Source
Expand description

§Positive

A type-safe wrapper for guaranteed positive decimal values.

This crate provides the Positive type, which encapsulates a Decimal value and ensures through its API that the contained value is always positive (greater than or equal to zero).

§Features

  • Type Safety: Compile-time guarantees that values are non-negative
  • Decimal Precision: Built on rust_decimal for accurate financial calculations
  • Rich API: Comprehensive arithmetic operations, conversions, and utilities
  • Serde Support: Full serialization/deserialization support

§Example

use positive::{Positive, pos};

let price = pos!(100.50);
let quantity = Positive::new(10.0).unwrap();
let total = price * quantity;

Re-exports§

pub use error::PositiveError;
pub use error::PositiveResult;

Modules§

error
Error types for the Positive decimal type.

Macros§

pos
Macro for creating a new Positive value with simplified syntax.
spos
A macro to create an optional Positive value from the given expression.

Structs§

Decimal
Re-export rust_decimal for convenience. Decimal represents a 128 bit representation of a fixed-precision decimal number. The finite set of values of type Decimal are of the form m / 10e, where m is an integer such that -296 < m < 296, and e is an integer between 0 and 28 inclusive.
Positive
A wrapper type that represents a guaranteed positive decimal value.

Constants§

EPSILON
Default epsilon value for approximate comparisons.

Functions§

is_positive
Determines if the given type parameter T is the Positive type.