[](https://crates.io/crates/vector-traits)
[](https://docs.rs/vector-traits)
[](https://ci.codeberg.org/repos/12855)
[](https://deps.rs/crate/vector-traits/0.3.4)

[](https://github.com/sponsors/eadf)
# 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 `GenericVector2` and `GenericVector3` traits.
- Generic scalar trait `GenericScalar` for a flexible scalar type handling.
- Basic vector traits `HasXY` and `HasXYZ` for custom vector storage types, e.g., FFI types.
- Seamless transition between different vector libraries like `cgmath` and `glam`.
- 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::Vec2`,`glam::DVec2`,`glam::Vec3`,`glam::Vec3A` and `glam::DVec3`
- `cgmath::Vector2` and`cgmath::Vector3` (for `f32` and `f64`)
## Usage
Add `vector-traits` to your `Cargo.toml` dependencies along with the desired features:
```toml
[dependencies]
vector-traits = { version = "0.3.4", features = ["glam", "cgmath"] } # only use what you need
```
## Documentation
For a deeper dive into vector-traits functionality, check the documentation generated by cargo doc or browse it online here.
## Contributing
We welcome contributions from the community.
Feel free to submit pull requests or report issues on our GitHub repository.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you,
as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
## License
Licensed under either of
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE)
or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT)
or http://opensource.org/licenses/MIT)
at your option.