From a6dc23203590c0cc1da80214bae1b70a9b0c8b63 Mon Sep 17 00:00:00 2001 From: Alex Parrill Date: Sat, 21 Oct 2023 22:30:59 -0400 Subject: [PATCH] Use mod paths instead of include This approach still allows using the same files for Rc and Arc while preventing imports from leaking as well as working better with rust-analyzer. --- src/array.rs | 5 +++++ src/lib.rs | 1 + src/map.rs | 8 +++++++- src/string.rs | 6 +++++- src/sync.rs | 17 ++++++++++++----- src/unsync.rs | 18 +++++++++++++----- 6 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/array.rs b/src/array.rs index 582a296..a400c1e 100644 --- a/src/array.rs +++ b/src/array.rs @@ -1,3 +1,8 @@ +use std::fmt; + +use super::Rc; +use crate::ImplicitClone; + /// An immutable array type inspired by [Immutable.js](https://immutable-js.com/). /// /// This type is cheap to clone and thus implements [`ImplicitClone`]. It can be created based on a diff --git a/src/lib.rs b/src/lib.rs index c4b3dfc..6f397de 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ #![warn(missing_debug_implementations, missing_docs, unreachable_pub)] #![allow(clippy::unnecessary_lazy_evaluations)] +#![allow(clippy::duplicate_mod)] #![doc(test( no_crate_inject, attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables)) diff --git a/src/map.rs b/src/map.rs index cc76f6e..7d1812b 100644 --- a/src/map.rs +++ b/src/map.rs @@ -3,8 +3,14 @@ use indexmap::map::Keys as MapKeys; use indexmap::map::Values as MapValues; use indexmap::IndexMap as Map; use std::borrow::Borrow; +use std::fmt; use std::hash::Hash; +use crate::ImplicitClone; + +use super::IString; +use super::Rc; + /// An immutable hash map type inspired by [Immutable.js](https://immutable-js.com/). /// /// This type is cheap to clone and thus implements [`ImplicitClone`]. It can be created based on a @@ -346,7 +352,7 @@ where for (k, v) in a.iter() { seq.serialize_entry(k, v)?; } - }, + } Self::Rc(a) => { for (k, v) in a.iter() { seq.serialize_entry(k, v)?; diff --git a/src/string.rs b/src/string.rs index 63bfbc4..20d1fcf 100644 --- a/src/string.rs +++ b/src/string.rs @@ -1,8 +1,12 @@ use std::borrow::Cow; use std::cmp::Ordering; -use std::fmt::Debug; +use std::fmt::{self, Debug}; use std::str::FromStr; +use crate::ImplicitClone; + +use super::Rc; + /// An immutable string type inspired by [Immutable.js](https://immutable-js.com/). /// /// This type is cheap to clone and thus implements [`ImplicitClone`]. It can be created based on a diff --git a/src/sync.rs b/src/sync.rs index 0fc319f..5dd53a0 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -1,11 +1,18 @@ +use std::sync::Arc as Rc; + use crate::ImplicitClone; -use std::fmt; -type Rc = std::sync::Arc; +#[path = "array.rs"] +mod array; +#[cfg(feature = "map")] +#[path = "map.rs"] +mod map; +#[path = "string.rs"] +mod string; -include!("string.rs"); -include!("array.rs"); +pub use array::IArray; #[cfg(feature = "map")] -include!("map.rs"); +pub use map::IMap; +pub use string::IString; impl ImplicitClone for Rc {} diff --git a/src/unsync.rs b/src/unsync.rs index 3f587d6..cada2a0 100644 --- a/src/unsync.rs +++ b/src/unsync.rs @@ -1,10 +1,18 @@ -use crate::ImplicitClone; -use std::fmt; use std::rc::Rc; -include!("string.rs"); -include!("array.rs"); +use crate::ImplicitClone; + +#[path = "array.rs"] +mod array; +#[cfg(feature = "map")] +#[path = "map.rs"] +mod map; +#[path = "string.rs"] +mod string; + +pub use array::IArray; #[cfg(feature = "map")] -include!("map.rs"); +pub use map::IMap; +pub use string::IString; impl ImplicitClone for Rc {}