num-traits

Numeric traits for generic mathematics in Rust, from Zero and One to Float and PrimInt

Library
Cargo
v0.2.19
972 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
52 /100 Fair
Development Activity 32
Maintenance 16
Community 72
Maturity 60
Momentum 28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
79 /100 Good
Architecture 85
Code Quality 82
Innovation 78
Learning Curve 70

num-traits defines a set of composable traits that let Rust code be generic over numeric types instead of hard-coding f32, f64, i32, or u64. It underpins the wider rust-num ecosystem (num, num-complex, num-bigint, num-rational) and is a dependency of thousands of crates that need to write one algorithm that works across integers, floats, and custom numeric types.

The crate is #![no_std] by default, so it works in embedded and kernel contexts, with an optional libm feature to bring floating-point operations (like sqrt or sin) to platforms without the standard library. Traits are split into small, focused pieces (Zero, One, Num, Float, PrimInt, Bounded, Signed) so generic code only needs to require the exact capabilities it uses.

What You Get

  • Identity and arithmetic traits: Zero, One, Num, NumOps, and their checked/saturating/wrapping variants
  • Float and FloatConst traits exposing transcendental operations (sqrt, sin, ln) generically, with libm support for no_std
  • PrimInt trait unifying integer-specific operations like bit rotation and leading/trailing zero counts
  • Bounded, Signed, and Unsigned traits for range and sign-aware generic code
  • AsPrimitive, FromPrimitive, ToPrimitive, and NumCast for ergonomic numeric conversions
  • Full no_std compatibility with an optional libm feature for float ops without the standard library

Common Use Cases

  • Writing a single generic function or struct that works over f32, f64, and every integer type without duplication
  • Building numeric libraries (linear algebra, statistics, physics simulation) that need to be generic over precision
  • Implementing custom numeric types (fixed-point, complex, big integers) that plug into the standard numeric trait ecosystem
  • Targeting embedded or no_std environments while still needing generic floating-point math via the libm feature

Under The Hood

Architecture num-traits organizes its API as a set of narrowly-scoped traits split across dedicated modules (bounds.rs, cast.rs, float.rs, identities.rs, int.rs, ops/, pow.rs, real.rs, sign.rs), each re-exported from lib.rs so consumers can use num_traits::{Zero, One, Float} directly; the crate itself contains no concrete numeric types, only trait definitions and blanket implementations for Rust’s built-in primitives, keeping it a pure abstraction layer that other rust-num crates (num-complex, num-bigint, num-rational) and downstream numeric libraries build concrete types against.

Tech Stack The crate is written in pure, dependency-light Rust (edition 2021, MSRV 1.60), with a single optional runtime dependency on libm for software floating-point implementations when std is disabled, and autocfg as a build-time dependency for detecting compiler capabilities; it is #![no_std] by default and gates std-only functionality (like native float transcendental functions) behind Cargo features, making it viable in embedded, WASM, and kernel-level contexts.

Code Quality The tests/ directory contains dedicated integration test files per concern area (e.g. cast.rs), and the crate additionally embeds extensive doctested examples directly in trait documentation, which double as both documentation and correctness checks under cargo test --doc; the code favors small, single-purpose traits with blanket impls over primitives, and CI (visible via the ci/ directory and GitHub Actions badge) exercises multiple feature combinations and MSRV compatibility.

API Design The API is deliberately minimal and composable — traits like Zero, One, and Num are small enough to be understood at a glance, and free functions (zero(), one(), pow(), cast()) offer ergonomic shortcuts alongside the trait methods; the tradeoff is that consumers need to understand Rust’s trait bound system to use it effectively, but this is standard for the idiomatic-generics niche the crate targets, and 131 contributors plus near-universal adoption across the Rust numeric ecosystem indicate the design has held up well over nearly a decade.

Used by 11 apps in this directory

Rust
54%
Other

Cap

Team Chat · Video Conferencing

22,884

Open source Loom alternative with GPU-accelerated recording, instant share links, AI summaries, and full self-hosting via Docker Compose.

View details
89
Repo Health
81
Technical
64
Dependency
Built with
Rust 54%
TypeScript 42%
Updated 4 days ago
Rust
99%
Other

Fluree DB

Databases

469

A temporal, verifiable graph database with git-like branching, integrated vector/text/geo search, and RDF/SPARQL/JSON-LD/openCypher support — benchmarked at 10.4x faster than the next database on the full Wikidata dump.

View details
87
Repo Health
74
Technical
65
Dependency
Built with
Rust 99%
Updated 5 days ago
Rust
95%
MIT

Fyrox

Game Development

9,568

A production-ready 2D/3D game engine written in Rust with a built-in scene editor, physics, and hot-reloading game scripts

View details
85
Repo Health
79
Technical
68
Dependency
Built with
Rust 95%
Updated 5 days ago
Rust
52%
Other

hoodik

File Storage · Security

1,484

Self-hosted, end-to-end encrypted cloud storage with browser-based encryption and S3-compatible storage support

View details
79
Repo Health
71
Technical
63
Dependency
Built with
Rust 52%
TypeScript 33%
Vue 14%
Updated 1 weeks ago
Rust
96%
Apache 2.0

InfluxDB

Analytics · Databases

31,758

Open-source time-series database built for real-time ingest, fast SQL queries, and embedded Python automation — powered by Apache Arrow and Parquet.

View details
82
Repo Health
76
Technical
72
Dependency
Built with
Rust 96%
Updated 1 weeks ago
TypeScript
77%
Other

Joplin

Note Taking

56,513

The privacy-first, open-source note-taking app with end-to-end encrypted sync, AI assistance, and a powerful plugin ecosystem across every platform.

View details
93
Repo Health
87
Technical
60
Dependency
Built with
TypeScript 77%
JavaScript 14%
Updated 5 days ago
C++
44%
BSD 2

Ladybird

Browser

66,342

A truly independent web browser built from scratch — no Chromium, no WebKit, no Gecko.

View details
76
Repo Health
82
Technical
81
Dependency
Built with
C++ 44%
HTML 23%
Rust 20%
Updated 4 days ago
Rust
86%
AGPL 3.0

ParadeDB

Analytics · Databases · Search

9,311

Born out of Y Combinator's S2023 batch, ParadeDB is a Postgres extension that delivers Elasticsearch-quality BM25 search and real-time analytics without a separate search cluster to manage.

View details
89
Repo Health
87
Technical
68
Dependency
Built with
Rust 86%
PLpgSQL 14%
Updated 4 days ago
Rust
63%
MIT

PostgresML

AI Development · Databases

6,825

Run ML training and LLM inference natively inside PostgreSQL with GPU acceleration — no data movement required.

View details
51
Repo Health
76
Technical
64
Dependency
Built with
Rust 63%
JavaScript 11%
Updated 1 years ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers