Przeglądaj źródła

:tada: first trait Float

Felix Bytow 2 lat temu
commit
832120f8b8
5 zmienionych plików z 52 dodań i 0 usunięć
  1. 11 0
      .gitignore
  2. 10 0
      Cargo.toml
  3. 3 0
      src/lib.rs
  4. 25 0
      src/traits/float.rs
  5. 3 0
      src/traits/mod.rs

+ 11 - 0
.gitignore

@@ -0,0 +1,11 @@
+# Rust
+/target
+/Cargo.lock
+
+# CLion/IDEA
+*.iml
+.idea/*
+!.idea/codeStyles/
+
+# MacOS
+.DS_Store

+ 10 - 0
Cargo.toml

@@ -0,0 +1,10 @@
+[package]
+name = "lineal"
+authors = ["Felix Bytow <drako@drako.guru>"]
+version = "0.1.0"
+edition = "2021"
+publish = ["crates-drako-guru"]
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]

+ 3 - 0
src/lib.rs

@@ -0,0 +1,3 @@
+pub use self::traits::Float;
+
+mod traits;

+ 25 - 0
src/traits/float.rs

@@ -0,0 +1,25 @@
+/// Marker trait because certain operations only make sense on floating point types.
+pub trait Float {}
+
+impl Float for f32 {}
+
+impl Float for f64 {}
+
+#[cfg(test)]
+mod tests {
+    use crate::Float;
+
+    fn is_float<T: Float>() -> bool {
+        true
+    }
+
+    #[test]
+    fn f32_is_a_float() {
+        assert!(is_float::<f64>());
+    }
+
+    #[test]
+    fn f64_is_a_float() {
+        assert!(is_float::<f64>());
+    }
+}

+ 3 - 0
src/traits/mod.rs

@@ -0,0 +1,3 @@
+pub use self::float::Float;
+
+mod float;