Expand description
§Vector-Traits Crate
vector-traits is a Rust crate designed to provide a set of traits for abstracting over different vector
implementations and scalar types, offering a unified interface for a basic set of vector operations. This crate facilitates
seamless transitions between different vector libraries and scalar precisions (e.g., f32 and f64) without
requiring significant code modifications.
§Features
- Abstract over two-dimensional and three-dimensional vectors with
GenericVector2andGenericVector3traits. - Generic scalar trait
GenericScalarfor a flexible scalar type handling. - Basic vector traits
HasXYandHasXYZfor down to metal, custom vector storage types, e.g., FFI types. - Seamless transition between different vector libraries like
cgmathandglam. - Ability to switch between different scalar types (
f32,f64) effortlessly.
§Supported Vector Implementations
Currently, the following vector types from cgmath and glam libraries are supported:
glam::Vec2glam::DVec2glam::Vec3glam::DVec3cgmath::Vector2cgmath::Vector3
§Usage
Add vector-traits to your Cargo.toml dependencies along with the desired features:
[dependencies]
vector-traits = { version = "0.3.4", features = ["glam", "cgmath"] } # only use what you need§Contributing
Contributions are welcome! Feel free to open an issue or submit a pull request.
§License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
Re-exports§
pub use approx;pub use num_traits;
Traits§
- Approx
- A workaround for Rust’s limitations where external traits cannot be implemented for external types.
- Generic
Scalar - A trait meant to to represent f32 or f64
- Generic
Vector2 - A generic two-dimensional vector trait, designed for flexibility in precision.
- Generic
Vector3 - A generic three-dimensional vector trait, designed for flexibility in precision.
- HasXY
- A basic two-dimensional vector trait, designed for flexibility in precision.
- HasXYZ
- A basic three-dimensional vector trait, designed for flexibility in precision.