diff --git a/Cargo.lock b/Cargo.lock index 4b495fe..e118232 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,65 +2,22 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "getrandom" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - [[package]] name = "identified_vec" version = "0.1.5" dependencies = [ + "identified_vec", "serde", + "serde_json", "thiserror", ] -[[package]] -name = "identified_vec_macros" -version = "0.1.5" -dependencies = [ - "identified_vec", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "itoa" version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" -[[package]] -name = "libc" -version = "0.2.151" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" - -[[package]] -name = "maplit" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" - -[[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - [[package]] name = "proc-macro2" version = "1.0.70" @@ -79,36 +36,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - [[package]] name = "ryu" version = "1.0.16" @@ -157,18 +84,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tests" -version = "0.1.0" -dependencies = [ - "identified_vec", - "identified_vec_macros", - "maplit", - "rand", - "serde", - "serde_json", -] - [[package]] name = "thiserror" version = "1.0.50" @@ -194,9 +109,3 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" diff --git a/Cargo.toml b/Cargo.toml index eaa688f..b98f31b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,25 @@ -[workspace] +[package] +name = "identified_vec" +version = "0.1.5" +edition = "2021" +authors = ["Alexander Cyon "] +description = "Like HashSet but retaining INSERTION order and without `Hash` requirement on the Element type." +license = "MIT" +readme = "README.md" +repository = "https://github.com/Sajjon/identified_vec" +keywords = ["identifiable", "vec", "orderset", "set", "hashset"] +categories = ["data-structures"] -resolver = "2" +[features] +default = ["id_prim"] +serde = ["dep:serde"] +id_prim = [] -members = ["identified_vec", "identified_vec_macros", "tests"] +[dependencies] +serde = { version = "1.0.193", optional = true } +thiserror = "1.0.50" + +[dev-dependencies] +identified_vec = { path = ".", features = ["id_prim", "serde"] } +serde = { version = "1.0.193", features = ["derive"] } +serde_json = "1.0.108" diff --git a/README.md b/README.md index 637203b..fc39419 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ You can create an identified vec with any element type that implements the `Iden ```rust extern crate identified_vec; -use identified_vec::{IsIdentifiableVec, IdentifiedVec, Identifiable, IdentifiedVecOf}; +use identified_vec::{IsIdentifiedVec, IdentifiedVec, Identifiable, IdentifiedVecOf}; use std::cell::RefCell; #[derive(Eq, PartialEq, Clone, Debug)] diff --git a/identified_vec/Cargo.lock b/identified_vec/Cargo.lock deleted file mode 100644 index 12f4005..0000000 --- a/identified_vec/Cargo.lock +++ /dev/null @@ -1,184 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "getrandom" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "identified_vec" -version = "0.1.4" -dependencies = [ - "identified_vec", - "maplit", - "rand", - "serde", - "serde_json", - "thiserror", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "libc" -version = "0.2.150" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" - -[[package]] -name = "maplit" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" - -[[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - -[[package]] -name = "proc-macro2" -version = "1.0.70" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "serde" -version = "1.0.193" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.193" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.108" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "syn" -version = "2.0.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" diff --git a/identified_vec/Cargo.toml b/identified_vec/Cargo.toml deleted file mode 100644 index 5014371..0000000 --- a/identified_vec/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "identified_vec" -version = "0.1.5" -edition = "2021" -authors = ["Alexander Cyon "] -description = "Like HashSet but retaining INSERTION order and without `Hash` requirement on the Element type." -license = "MIT" -readme = "../README.md" -repository = "https://github.com/Sajjon/identified_vec" -keywords = ["identifiable", "vec", "orderset", "set", "hashset"] -categories = ["data-structures"] - -[features] -default = ["id_prim"] -serde = ["dep:serde"] -id_prim = [] - -[dependencies] -serde = { version = "1.0.193", optional = true } -thiserror = "1.0.50" \ No newline at end of file diff --git a/identified_vec_macros/Cargo.toml b/identified_vec_macros/Cargo.toml deleted file mode 100644 index 063e667..0000000 --- a/identified_vec_macros/Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[package] -name = "identified_vec_macros" -version = "0.1.5" -edition = "2021" -authors = ["Alexander Cyon "] -description = "A macro which allows you to create IdentifiedVecOf newtypes which act as if they were IdentifiedVecOf." -license = "MIT" -readme = "../README.md" -repository = "https://github.com/Sajjon/identified_vec" -keywords = [ - "identified_vec_of", - "newtype", - "via", - "identifiable", - "identified_vec", -] -categories = ["data-structures"] - -[dependencies] -identified_vec = { version = "0.1.5", path = "../identified_vec" } -proc-macro2 = "1.0.70" -quote = "1.0" -syn = { version = "2.0", features = ["extra-traits", "full", "parsing"] } diff --git a/identified_vec/src/identified_vec_into_iterator.rs b/src/iterators/identified_vec_into_iterator.rs similarity index 90% rename from identified_vec/src/identified_vec_into_iterator.rs rename to src/iterators/identified_vec_into_iterator.rs index 4eb7f1a..ea0faf4 100644 --- a/identified_vec/src/identified_vec_into_iterator.rs +++ b/src/iterators/identified_vec_into_iterator.rs @@ -1,8 +1,8 @@ -use crate::is_identifiable_vec::IsIdentifiableVec; -use crate::vec::IdentifiedVec; use std::fmt::Debug; use std::hash::Hash; +use crate::{IdentifiedVec, IsIdentifiedVec}; + /// An owning iterator over the items of an `IdentifiedVec`. pub struct IdentifiedVecIntoIterator where diff --git a/identified_vec/src/identified_vec_iterator.rs b/src/iterators/identified_vec_iterator.rs similarity index 91% rename from identified_vec/src/identified_vec_iterator.rs rename to src/iterators/identified_vec_iterator.rs index e63a5f1..5bfad84 100644 --- a/identified_vec/src/identified_vec_iterator.rs +++ b/src/iterators/identified_vec_iterator.rs @@ -1,8 +1,8 @@ -use crate::is_identifiable_vec::IsIdentifiableVec; -use crate::vec::IdentifiedVec; use std::fmt::Debug; use std::hash::Hash; +use crate::{IdentifiedVec, IsIdentifiedVec}; + /// An iterator over the items of an `IdentifiedVec`. pub struct IdentifiedVecIterator<'a, I, E> where diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs new file mode 100644 index 0000000..bf6c684 --- /dev/null +++ b/src/iterators/mod.rs @@ -0,0 +1,2 @@ +pub mod identified_vec_into_iterator; +pub mod identified_vec_iterator; diff --git a/identified_vec/src/lib.rs b/src/lib.rs similarity index 83% rename from identified_vec/src/lib.rs rename to src/lib.rs index 6dd5419..05097e1 100644 --- a/identified_vec/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,8 @@ //! //! ``` //! extern crate identified_vec; -//! use identified_vec::{IsIdentifiableVec, IsIdentifiableVecOf, IdentifiedVec, IdentifiedVecOf, Identifiable}; +//! use identified_vec::identified_vec::*; +//! use identified_vec::identified_vec_of::*; //! use std::cell::RefCell; //! //! #[derive(Eq, PartialEq, Clone, Debug)] @@ -110,30 +111,19 @@ //! //! ``` //! extern crate identified_vec; -//! use identified_vec::{IsIdentifiableVec, IdentifiedVec, IdentifiedVecOf, Identifiable}; -//! +//! use identified_vec::identified_vec::*; +//! use identified_vec::identified_vec_of::*; //! // closure which plucks out an ID from an element. //! let numbers = IdentifiedVec::::new_identifying_element(|e| *e); //! ``` -mod conflict_resolution_choice; -mod errors; -mod identifiable_trait; -mod identified_vec_into_iterator; -mod identified_vec_iterator; -mod is_identifiable_vec; -mod is_identifiable_vec_of; -mod is_identified_vec_via; -mod primitives_identifiable; +mod iterators; mod vec; mod vec_of; pub mod identified_vec { //! A collection of unique identifiable elements which retains **insertion** order. - pub use crate::conflict_resolution_choice::*; - pub use crate::identified_vec_into_iterator::*; - pub use crate::identified_vec_iterator::*; - pub use crate::is_identifiable_vec::*; + pub use crate::iterators::*; pub use crate::vec::*; } @@ -143,15 +133,7 @@ pub mod identified_vec_of { //! `IdentifiedVec` but also allows you to //! skip the `id_of_element: fn(&Element) -> ID` closure when //! initializing a new identified vec. - pub use crate::identifiable_trait::*; - pub use crate::is_identifiable_vec_of::*; - pub use crate::is_identified_vec_via::*; pub use crate::vec_of::*; - - #[cfg(feature = "id_prim")] - pub use crate::primitives_identifiable::*; - - pub use crate::errors::*; } pub use crate::identified_vec::*; diff --git a/identified_vec/src/conflict_resolution_choice.rs b/src/vec/conflict_resolution_choice.rs similarity index 100% rename from identified_vec/src/conflict_resolution_choice.rs rename to src/vec/conflict_resolution_choice.rs diff --git a/identified_vec/src/vec.rs b/src/vec/identified_vec.rs similarity index 97% rename from identified_vec/src/vec.rs rename to src/vec/identified_vec.rs index 9957d02..3fae1c6 100644 --- a/identified_vec/src/vec.rs +++ b/src/vec/identified_vec.rs @@ -1,12 +1,12 @@ -use crate::conflict_resolution_choice::ConflictResolutionChoice; -use crate::errors::Error; -use crate::identified_vec_into_iterator::IdentifiedVecIntoIterator; -use crate::identified_vec_iterator::IdentifiedVecIterator; +use super::ConflictResolutionChoice; +use crate::iterators::identified_vec_into_iterator::IdentifiedVecIntoIterator; +use crate::iterators::identified_vec_iterator::IdentifiedVecIterator; +use crate::Error; use std::collections::HashMap; use std::fmt::{Debug, Display}; use std::hash::{Hash, Hasher}; -use crate::is_identifiable_vec::IsIdentifiableVec; +use super::is_identified_vec::IsIdentifiedVec; /// An ordered collection of identifiable elements. /// @@ -26,7 +26,7 @@ use crate::is_identifiable_vec::IsIdentifiableVec; /// /// ``` /// extern crate identified_vec; -/// use identified_vec::{IdentifiedVec, Identifiable, IdentifiedVecOf, IsIdentifiableVec, IsIdentifiableVecOf}; +/// use identified_vec::{IdentifiedVec, Identifiable, IdentifiedVecOf, IsIdentifiedVec, IsIdentifiedVecOf}; /// use std::cell::RefCell; /// /// #[derive(Eq, PartialEq, Clone, Debug)] @@ -124,7 +124,7 @@ use crate::is_identifiable_vec::IsIdentifiableVec; /// /// ``` /// /// extern crate identified_vec; -/// use identified_vec::{IdentifiedVec, Identifiable, IdentifiedVecOf, IsIdentifiableVec, IsIdentifiableVecOf}; +/// use identified_vec::{IdentifiedVec, Identifiable, IdentifiedVecOf, IsIdentifiedVec, IsIdentifiedVecOf}; /// /// let numbers = IdentifiedVec::::new_identifying_element(|e| *e); /// ``` @@ -172,7 +172,7 @@ where pub(crate) _id_of_element: fn(&E) -> I, } -impl IsIdentifiableVec for IdentifiedVec +impl IsIdentifiedVec for IdentifiedVec where I: Eq + Hash + Clone + Debug, { @@ -328,7 +328,7 @@ where /// /// ``` /// extern crate identified_vec; - /// use identified_vec::{IsIdentifiableVec, IsIdentifiableVecOf, IdentifiedVec, Identifiable, IdentifiedVecOf}; + /// use identified_vec::{IsIdentifiedVec, IsIdentifiedVecOf, IdentifiedVec, Identifiable, IdentifiedVecOf}; /// /// #[derive(Eq, PartialEq, Clone, Debug, Hash)] /// struct User { @@ -550,7 +550,7 @@ where /// /// ``` /// extern crate identified_vec; - /// use identified_vec::{IsIdentifiableVec, IsIdentifiableVecOf, IdentifiedVec, Identifiable, IdentifiedVecOf}; + /// use identified_vec::{IsIdentifiedVec, IsIdentifiedVecOf, IdentifiedVec, Identifiable, IdentifiedVecOf}; /// /// #[derive(Eq, PartialEq, Clone, Debug, Hash)] /// struct User { diff --git a/identified_vec/src/is_identifiable_vec.rs b/src/vec/is_identified_vec.rs similarity index 96% rename from identified_vec/src/is_identifiable_vec.rs rename to src/vec/is_identified_vec.rs index 04a5a9c..b65c6c5 100644 --- a/identified_vec/src/is_identifiable_vec.rs +++ b/src/vec/is_identified_vec.rs @@ -1,10 +1,9 @@ -use crate::conflict_resolution_choice::ConflictResolutionChoice; -use crate::Error; -use crate::IdentifiedVecIterator; +use crate::iterators::identified_vec_iterator::IdentifiedVecIterator; +use crate::{ConflictResolutionChoice, Error}; use std::fmt::Debug; use std::hash::Hash; -pub trait IsIdentifiableVec: Sized +pub trait IsIdentifiedVec: Sized where ID: Eq + Hash + Clone + Debug, { @@ -57,7 +56,7 @@ where /// /// ``` /// extern crate identified_vec; - /// use identified_vec::{IsIdentifiableVec, IsIdentifiableVecOf, IdentifiedVec, Identifiable, IdentifiedVecOf}; + /// use identified_vec::{IsIdentifiedVec, IsIdentifiedVecOf, IdentifiedVec, Identifiable, IdentifiedVecOf}; /// /// #[derive(Eq, PartialEq, Clone, Debug, Hash)] /// struct User { @@ -188,7 +187,7 @@ where /// /// ``` /// extern crate identified_vec; - /// use identified_vec::{IsIdentifiableVec, IsIdentifiableVecOf, IdentifiedVec, Identifiable, IdentifiedVecOf}; + /// use identified_vec::{IsIdentifiedVec, IsIdentifiedVecOf, IdentifiedVec, Identifiable, IdentifiedVecOf}; /// /// #[derive(Eq, PartialEq, Clone, Debug, Hash)] /// struct User { diff --git a/src/vec/mod.rs b/src/vec/mod.rs new file mode 100644 index 0000000..60944b4 --- /dev/null +++ b/src/vec/mod.rs @@ -0,0 +1,7 @@ +mod conflict_resolution_choice; +mod identified_vec; +mod is_identified_vec; + +pub use conflict_resolution_choice::*; +pub use identified_vec::*; +pub use is_identified_vec::*; diff --git a/identified_vec/src/errors.rs b/src/vec_of/errors.rs similarity index 100% rename from identified_vec/src/errors.rs rename to src/vec_of/errors.rs diff --git a/identified_vec/src/identifiable_trait.rs b/src/vec_of/identifiable_trait.rs similarity index 100% rename from identified_vec/src/identifiable_trait.rs rename to src/vec_of/identifiable_trait.rs diff --git a/identified_vec/src/vec_of.rs b/src/vec_of/identified_vec_of.rs similarity index 95% rename from identified_vec/src/vec_of.rs rename to src/vec_of/identified_vec_of.rs index 1270110..b73e922 100644 --- a/identified_vec/src/vec_of.rs +++ b/src/vec_of/identified_vec_of.rs @@ -4,16 +4,14 @@ use std::collections::HashMap; use std::fmt::Debug; #[cfg(feature = "serde")] -use crate::errors::IdentifiedVecOfSerdeFailure; -use crate::IsIdentifiableVecOf; -use crate::{ - conflict_resolution_choice::ConflictResolutionChoice, is_identifiable_vec::IsIdentifiableVec, -}; -use crate::{identified_vec_of::Identifiable, vec::IdentifiedVec}; +use super::errors::IdentifiedVecOfSerdeFailure; +use crate::{ConflictResolutionChoice, IdentifiedVec, IsIdentifiedVec, IsIdentifiedVecOf}; #[cfg(feature = "serde")] use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; +use super::identifiable_trait::Identifiable; + /////////////////////// /// IdentifiedVecOf /// /////////////////////// @@ -28,7 +26,7 @@ use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; /// `Element` implements serde serialization/deserialization of course. pub type IdentifiedVecOf = IdentifiedVec<::ID, Element>; -impl IsIdentifiableVecOf for IdentifiedVecOf +impl IsIdentifiedVecOf for IdentifiedVecOf where Element: Identifiable, { diff --git a/identified_vec/src/is_identifiable_vec_of.rs b/src/vec_of/is_identified_vec_of.rs similarity index 93% rename from identified_vec/src/is_identifiable_vec_of.rs rename to src/vec_of/is_identified_vec_of.rs index 247fe7a..b6002be 100644 --- a/identified_vec/src/is_identifiable_vec_of.rs +++ b/src/vec_of/is_identified_vec_of.rs @@ -1,10 +1,6 @@ -use crate::identifiable_trait::Identifiable; -use crate::is_identifiable_vec::IsIdentifiableVec; -use crate::ConflictResolutionChoice; +use crate::{ConflictResolutionChoice, Identifiable, IsIdentifiedVec}; -pub trait IsIdentifiableVecOf: - IsIdentifiableVec -{ +pub trait IsIdentifiedVecOf: IsIdentifiedVec { /// Constructs a new, empty `IdentifiedVec`, using `id()` on `Element` /// as id function. fn new() -> Self; diff --git a/identified_vec/src/is_identified_vec_via.rs b/src/vec_of/is_identified_vec_of_via.rs similarity index 92% rename from identified_vec/src/is_identified_vec_via.rs rename to src/vec_of/is_identified_vec_of_via.rs index 9ada762..34e06f5 100644 --- a/identified_vec/src/is_identified_vec_via.rs +++ b/src/vec_of/is_identified_vec_of_via.rs @@ -1,15 +1,15 @@ -use crate::conflict_resolution_choice::ConflictResolutionChoice; -use crate::vec::ItemsCloned; use crate::{ - Error, Identifiable, IdentifiedVecIterator, IdentifiedVecOf, IsIdentifiableVec, - IsIdentifiableVecOf, + identified_vec_iterator::IdentifiedVecIterator, ConflictResolutionChoice, Error, + IsIdentifiedVec, IsIdentifiedVecOf, ItemsCloned, }; +use super::{identifiable_trait::Identifiable, identified_vec_of::IdentifiedVecOf}; + /// https://stackoverflow.com/a/66537661/1311272 pub trait ViaMarker {} pub trait IsIdentifiableVecOfVia: - IsIdentifiableVecOf + IntoIterator + ViaMarker + IsIdentifiedVecOf + IntoIterator + ViaMarker where Element: Identifiable, { @@ -18,7 +18,7 @@ where fn via(&self) -> &IdentifiedVecOf; } -impl IsIdentifiableVecOf for U +impl IsIdentifiedVecOf for U where U: ViaMarker, Element: Identifiable, @@ -49,7 +49,7 @@ where } } -impl IsIdentifiableVec for U +impl IsIdentifiedVec for U where U: ViaMarker, Element: Identifiable, diff --git a/src/vec_of/mod.rs b/src/vec_of/mod.rs new file mode 100644 index 0000000..f0f6998 --- /dev/null +++ b/src/vec_of/mod.rs @@ -0,0 +1,17 @@ +mod errors; +mod identifiable_trait; +mod identified_vec_of; +mod is_identified_vec_of; +mod is_identified_vec_of_via; +mod newtype_identified_vec_of; +mod primitives_identifiable; + +pub use errors::*; +pub use identifiable_trait::*; +pub use identified_vec_of::*; +pub use is_identified_vec_of::*; +pub use is_identified_vec_of_via::*; +pub use newtype_identified_vec_of::*; + +#[cfg(feature = "id_prim")] +pub use primitives_identifiable::*; diff --git a/identified_vec_macros/src/lib.rs b/src/vec_of/newtype_identified_vec_of.rs similarity index 67% rename from identified_vec_macros/src/lib.rs rename to src/vec_of/newtype_identified_vec_of.rs index c7ee743..f30b6bd 100644 --- a/identified_vec_macros/src/lib.rs +++ b/src/vec_of/newtype_identified_vec_of.rs @@ -2,7 +2,7 @@ //! a newtype wrapping an `IdentifiedVecOf` of the item type //! you pass in, but it gets super powers! It implements the //! traits `IsIdentifiableVecOfVia`, which implements the trait -//! `IsIdentifiableVecOf`, meaning that the declared newtype, +//! `IsIdentifiedVecOf`, meaning that the declared newtype, //! gets all the methods and functions of a `IdentifiedVecOf`, //! and if you use the `"serde"` feature, it is also //! (de)serializable. @@ -10,9 +10,7 @@ //! You use it like so: //! ``` //! extern crate identified_vec; -//! extern crate identified_vec_macros; -//! use identified_vec_macros::newtype_identified_vec; -//! use identified_vec::{IsIdentifiableVecOfVia, ViaMarker, IsIdentifiableVec, IsIdentifiableVecOf, IdentifiedVec, IdentifiedVecOf, Identifiable}; +//! use identified_vec::{IsIdentifiableVecOfVia, ViaMarker, IsIdentifiedVec, IsIdentifiedVecOf, IdentifiedVec, IdentifiedVecOf, Identifiable, newtype_identified_vec}; //! //! newtype_identified_vec!(of: u32, named: Ints);; //! @@ -23,11 +21,11 @@ #[macro_export] macro_rules! newtype_identified_vec { (of: $item_ty: ty, named: $struct_name: ident) => { - #[derive(Debug, Clone, Eq, PartialEq)] + #[derive(std::fmt::Debug, Clone, Eq, PartialEq)] pub struct $struct_name(IdentifiedVecOf<$item_ty>); - impl ViaMarker for $struct_name {} - impl IsIdentifiableVecOfVia<$item_ty> for $struct_name { + impl identified_vec::ViaMarker for $struct_name {} + impl identified_vec::IsIdentifiableVecOfVia<$item_ty> for $struct_name { fn via_mut(&mut self) -> &mut IdentifiedVecOf<$item_ty> { &mut self.0 } @@ -49,8 +47,10 @@ macro_rules! newtype_identified_vec { impl IntoIterator for $struct_name { type Item = $item_ty; - type IntoIter = - identified_vec::IdentifiedVecIntoIterator<<$item_ty as Identifiable>::ID, $item_ty>; + type IntoIter = identified_vec::identified_vec_into_iterator::IdentifiedVecIntoIterator< + <$item_ty as Identifiable>::ID, + $item_ty, + >; fn into_iter(self) -> Self::IntoIter { Self::IntoIter::new(self.0) @@ -58,31 +58,32 @@ macro_rules! newtype_identified_vec { } #[cfg(any(test, feature = "serde"))] - impl Serialize for $struct_name + impl serde::Serialize for $struct_name where - $item_ty: Serialize + Identifiable + Debug + Clone, + $item_ty: serde::Serialize + Identifiable + std::fmt::Debug + Clone, { fn serialize( &self, serializer: S, - ) -> Result<::Ok, ::Error> + ) -> Result<::Ok, ::Error> where - S: Serializer, + S: serde::Serializer, { IdentifiedVecOf::serialize(&self.0, serializer) } } #[cfg(any(test, feature = "serde"))] - impl<'de> Deserialize<'de> for $struct_name + impl<'de> serde::Deserialize<'de> for $struct_name where - $item_ty: Deserialize<'de> + Identifiable + Debug + Clone, + $item_ty: serde::Deserialize<'de> + Identifiable + std::fmt::Debug + Clone, { #[cfg(not(tarpaulin_include))] // false negative - fn deserialize>( + fn deserialize>( deserializer: D, ) -> Result<$struct_name, D::Error> { let id_vec_of = IdentifiedVecOf::<$item_ty>::deserialize(deserializer)?; + use identified_vec::IsIdentifiableVecOfVia; return Ok(Self::from_identified_vec_of(id_vec_of)); } } diff --git a/identified_vec/src/primitives_identifiable.rs b/src/vec_of/primitives_identifiable.rs similarity index 100% rename from identified_vec/src/primitives_identifiable.rs rename to src/vec_of/primitives_identifiable.rs diff --git a/tests/Cargo.toml b/tests/Cargo.toml deleted file mode 100644 index bee30e4..0000000 --- a/tests/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -# https://stackoverflow.com/a/71461114/1311272 -[package] -name = "tests" -version = "0.1.0" -edition = "2021" -publish = false - -[features] -default = ["serde"] -serde = ["dep:serde"] - -[dependencies] -identified_vec = { path = "../identified_vec", features = ["id_prim", "serde"] } -identified_vec_macros = { path = "../identified_vec_macros" } -serde = { version = "1.0.193", features = ["derive"], optional = true } -serde_json = "1.0.108" -rand = "0.8.5" -maplit = "1.0.2" - -[[test]] -name = "integration_tests" -path = "tests.rs" diff --git a/tests/tests.rs b/tests/tests.rs index e273681..5479ce6 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,15 +1,11 @@ use std::{cell::RefCell, collections::HashSet, fmt::Debug, ops::Deref}; use identified_vec::{ - ConflictResolutionChoice, Error, Identifiable, IdentifiedVec, IdentifiedVecOf, - IdentifiedVecOfSerdeFailure, IsIdentifiableVec, IsIdentifiableVecOf, IsIdentifiableVecOfVia, - ItemsCloned, ViaMarker, + newtype_identified_vec, ConflictResolutionChoice, Error, Identifiable, IdentifiedVec, + IdentifiedVecOf, IdentifiedVecOfSerdeFailure, IsIdentifiedVec, IsIdentifiedVecOf, ItemsCloned, }; - #[cfg(any(test, feature = "serde"))] -use serde::{Deserialize, Deserializer, Serialize, Serializer}; - -use identified_vec_macros::newtype_identified_vec; +use serde::{Deserialize, Serialize}; #[derive(Eq, PartialEq, Clone)] #[cfg_attr(any(test, feature = "serde"), derive(Serialize, Deserialize))]