diff --git a/.hooks/pre-commit b/.hooks/pre-commit index 6a82602..5396a51 100755 --- a/.hooks/pre-commit +++ b/.hooks/pre-commit @@ -1,7 +1,6 @@ #!/bin/sh cargo readme -o README.md -cargo readme -r default-for -o README.md cargo readme -r derive-bounded -o README.md cargo readme -r optimal-core -o README.md cargo readme -r optimal-pbil -o README.md diff --git a/Cargo.lock b/Cargo.lock index ef7ac2d..37ef771 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -70,10 +70,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" -[[package]] -name = "default-for" -version = "0.1.0" - [[package]] name = "derive-bounded" version = "0.1.0" @@ -225,7 +221,6 @@ dependencies = [ name = "optimal-pbil" version = "0.1.0" dependencies = [ - "default-for", "derive-bounded", "derive-getters", "derive_more", @@ -246,7 +241,6 @@ dependencies = [ name = "optimal-steepest" version = "0.1.0" dependencies = [ - "default-for", "derive-bounded", "derive-getters", "derive_more", diff --git a/Cargo.toml b/Cargo.toml index 814ebc6..cbcd859 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,5 @@ [workspace] members = [ - "default-for", "derive-bounded", "optimal-binary", "optimal-core", diff --git a/default-for/Cargo.toml b/default-for/Cargo.toml deleted file mode 100644 index b52ba3a..0000000 --- a/default-for/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "default-for" -version = "0.1.0" -edition = "2021" -authors = ["Justin Lovinger"] -description = "Generalization of the `Default` trait" -repository = "https://github.com/justinlovinger/optimal-rs" -readme = "README.md" -keywords = ["trait"] -categories = ["rust-patterns"] -license = "MIT" - -[dependencies] - -[dev-dependencies] diff --git a/default-for/README.md b/default-for/README.md deleted file mode 100644 index 2dd07d5..0000000 --- a/default-for/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# default-for - -License: MIT diff --git a/default-for/src/lib.rs b/default-for/src/lib.rs deleted file mode 100644 index 55436b0..0000000 --- a/default-for/src/lib.rs +++ /dev/null @@ -1,15 +0,0 @@ -/// A type with a default value -/// parameterized on another value. -pub trait DefaultFor { - /// Return a default value for `x`. - fn default_for(x: T) -> Self; -} - -impl DefaultFor for T -where - T: Default, -{ - fn default_for(_: A) -> Self { - T::default() - } -} diff --git a/derive-num-bounded/README.md b/derive-num-bounded/README.md new file mode 100644 index 0000000..e0e8ea3 --- /dev/null +++ b/derive-num-bounded/README.md @@ -0,0 +1,3 @@ +# derive-bounded + +License: MIT diff --git a/optimal-pbil/Cargo.toml b/optimal-pbil/Cargo.toml index accaf62..8070d08 100644 --- a/optimal-pbil/Cargo.toml +++ b/optimal-pbil/Cargo.toml @@ -14,7 +14,6 @@ license = "MIT" serde = ["dep:serde", "rand/serde1", "rand_xoshiro/serde1"] [dependencies] -default-for = { path = "../default-for" } derive-bounded = { path = "../derive-bounded" } derive-getters = "0.3.0" derive_more = "0.99.17" diff --git a/optimal-pbil/src/lib.rs b/optimal-pbil/src/lib.rs index 533a225..c5a17e3 100644 --- a/optimal-pbil/src/lib.rs +++ b/optimal-pbil/src/lib.rs @@ -23,7 +23,6 @@ mod state_machine; mod types; mod until_probabilities_converged; -use default_for::DefaultFor; use derive_getters::{Dissolve, Getters}; use derive_more::IsVariant; pub use optimal_core::prelude::*; @@ -191,8 +190,9 @@ impl Config { } } -impl DefaultFor for Config { - fn default_for(num_bits: usize) -> Self { +impl Config { + /// Return default 'Config'. + pub fn default_for(num_bits: usize) -> Self { Self { num_samples: NumSamples::default(), adjust_rate: AdjustRate::default(), @@ -200,9 +200,7 @@ impl DefaultFor for Config { mutation_adjust_rate: MutationAdjustRate::default(), } } -} -impl Config { /// Return this optimizer default /// running on the given problem. /// diff --git a/optimal-pbil/src/types.rs b/optimal-pbil/src/types.rs index 4ab5c1b..4c23c34 100644 --- a/optimal-pbil/src/types.rs +++ b/optimal-pbil/src/types.rs @@ -1,7 +1,6 @@ use core::convert::TryFrom; use std::f64::EPSILON; -use default_for::DefaultFor; use derive_bounded::{ derive_from_str_from_try_into, derive_into_inner, derive_new_from_bounded_float, derive_new_from_lower_bounded, derive_try_from_from_new, @@ -87,10 +86,10 @@ impl Ord for AdjustRate { #[cfg_attr(feature = "serde", serde(try_from = "f64"))] pub struct MutationChance(f64); -impl DefaultFor for MutationChance { +impl MutationChance { /// Return recommended default mutation chance, /// average of one mutation per step. - fn default_for(num_bits: usize) -> Self { + pub fn default_for(num_bits: usize) -> Self { if num_bits == 0 { Self(1.) } else { diff --git a/optimal-steepest/Cargo.toml b/optimal-steepest/Cargo.toml index 68f41fe..c37a9be 100644 --- a/optimal-steepest/Cargo.toml +++ b/optimal-steepest/Cargo.toml @@ -14,7 +14,6 @@ license = "MIT" serde = ["dep:serde"] [dependencies] -default-for = { path = "../default-for" } derive-bounded = { path = "../derive-bounded" } derive-getters = "0.3.0" derive_more = "0.99.17"