num-traits

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

Library
Cargo
v0.2.19
960stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
55/100Fair
Development Activity44
Maintenance16
Community72
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
79/100Good
Architecture85
Code Quality82
Innovation78
Learning Curve70

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

TypeScript
55%
Other

Cap

Team Chat · Video Conferencing

20,986

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
65
Dependency
Built with
TypeScript55%
Rust40%
Updated yesterday
Rust
100%
Other

Fluree DB

Databases

445

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
86
Repo Health
74
Technical
65
Dependency
Built with
Rust100%
Updated yesterday
Rust
95%
MIT

Fyrox

Game Development

9,512

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
Rust95%
Updated yesterday
Rust
50%
Other

hoodik

File Storage · Security

1,446

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

View details
74
Repo Health
71
Technical
65
Dependency
Built with
Rust50%
TypeScript33%
Vue15%
Updated 4 days ago
Rust
96%
Apache 2.0

InfluxDB

Databases · Analytics

31,705

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
86
Repo Health
76
Technical
72
Dependency
Built with
Rust96%
Updated yesterday
TypeScript
76%
Other

Joplin

Note Taking

56,003

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
62
Dependency
Built with
TypeScript76%
JavaScript15%
Updated yesterday
C++
49%
BSD 2

Ladybird

Browser

65,734

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

View details
75
Repo Health
82
Technical
82
Dependency
Built with
C++49%
HTML22%
Rust14%
Updated today
Rust
87%
AGPL 3.0

ParadeDB

Search · Databases · Analytics

9,175

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
88
Repo Health
87
Technical
71
Dependency
Built with
Rust87%
PLpgSQL12%
Updated today
Rust
63%
MIT

PostgresML

Databases · AI Development

6,817

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

View details
51
Repo Health
76
Technical
65
Dependency
Built with
Rust63%
JavaScript11%
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

Search