Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

### v0.5.8
- add `IntoMint` trait for unique conversions ([#68])

[#68]: https://github.com/kvark/mint/pull/68

### v0.5.7 (25-09-2021)
- update to rust2018
- implement `From<mint::Xxx>` for fixed-size arrays
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mint"
version = "0.5.7"
version = "0.5.8"
edition = "2018"
authors = [
"Benjamin Saunders <[email protected]>",
Expand Down
13 changes: 13 additions & 0 deletions src/into_mint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// Defines which mint type a given type is associated with. This trait enables
/// converting a type into its mint equivalent without having to name the mint
/// type.
///
/// Implementing `IntoMint` on a type states that the type is semantically
/// equivalent to the type given in `MintType`.
///
/// All mint types implement `IntoMint` reflexively, i.e., they implement
/// `IntoMint<MintType = Self>`.
pub trait IntoMint: Into<Self::MintType> {
/// The mint type that this type is associated with.
type MintType;
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ Designed to serve as an interoperability standard between libraries.
clippy::all
)]

mod into_mint;
mod matrix;
mod rotation;
mod vector;

pub use into_mint::*;
pub use matrix::*;
pub use rotation::*;
pub use vector::*;
5 changes: 5 additions & 0 deletions src/matrix.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::vector::{Vector2, Vector3, Vector4};
use crate::IntoMint;

macro_rules! matrix {
($name:ident : $vec:ident[ $($field:ident[$($sub:ident),*] = $index:expr),* ] = ($inner:expr, $outer:expr)) => {
Expand All @@ -9,6 +10,10 @@ macro_rules! matrix {
$( pub $field : $vec<T>, )*
}

impl<T> IntoMint for $name<T> {
type MintType = $name<T>;
}

impl<T> From<[[T; $inner]; $outer]> for $name<T> {
fn from([$($field),*]: [[T; $inner]; $outer]) -> Self {
$name {
Expand Down
5 changes: 5 additions & 0 deletions src/rotation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::vector::Vector3;
use crate::IntoMint;
use core::marker::PhantomData;

/// Standard quaternion represented by the scalar and vector parts.
Expand All @@ -13,6 +14,10 @@ pub struct Quaternion<T> {
pub s: T,
}

impl<T> IntoMint for Quaternion<T> {
type MintType = Quaternion<T>;
}

impl<T> From<[T; 4]> for Quaternion<T> {
fn from([x, y, z, s]: [T; 4]) -> Self {
Quaternion {
Expand Down
6 changes: 6 additions & 0 deletions src/vector.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::IntoMint;

macro_rules! vec {
($name:ident [ $($field:ident),* ] = $fixed:ty) => {
#[derive(Clone, Copy, Debug, Hash, PartialEq, PartialOrd, Eq, Ord)]
Expand All @@ -7,6 +9,10 @@ macro_rules! vec {
$( pub $field : T, )*
}

impl<T> IntoMint for $name<T> {
type MintType = $name<T>;
}

impl<T> From<$fixed> for $name<T> {
fn from([$($field),*]: $fixed) -> Self {
$name {
Expand Down