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 1aa0557
Show file tree
Hide file tree
Showing 5 changed files with 42 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
8 changes: 7 additions & 1 deletion src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)?;
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"]

Check failure on line 5 in src/sync.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, latest)

file is loaded as a module multiple times: `src/array.rs`

Check failure on line 5 in src/sync.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, 1.9.3)

file is loaded as a module multiple times: `src/array.rs`
mod array;
#[cfg(feature = "map")]

Check failure on line 7 in src/sync.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, latest)

file is loaded as a module multiple times: `src/map.rs`

Check failure on line 7 in src/sync.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, 1.9.3)

file is loaded as a module multiple times: `src/map.rs`
#[path = "map.rs"]
mod map;
#[path = "string.rs"]

Check failure on line 10 in src/sync.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, latest)

file is loaded as a module multiple times: `src/string.rs`

Check failure on line 10 in src/sync.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable, 1.9.3)

file is loaded as a module multiple times: `src/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 1aa0557

Please sign in to comment.