Skip to content

Commit

Permalink
Use mod paths instead of include
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ColonelThirtyTwo committed Oct 22, 2023
1 parent b981974 commit d60808c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/array.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use indexmap::IndexMap as Map;
use std::borrow::Borrow;
use std::hash::Hash;

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
Expand Down Expand Up @@ -346,7 +348,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)?;
Expand Down
6 changes: 5 additions & 1 deletion src/string.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 12 additions & 5 deletions src/sync.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
use std::sync::Arc as Rc;

use crate::ImplicitClone;
use std::fmt;

type Rc<T> = std::sync::Arc<T>;
#[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<T: ?Sized> ImplicitClone for Rc<T> {}
18 changes: 13 additions & 5 deletions src/unsync.rs
Original file line number Diff line number Diff line change
@@ -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<T: ?Sized> ImplicitClone for Rc<T> {}

0 comments on commit d60808c

Please sign in to comment.