Skip to content

Commit

Permalink
Merge branch 'main' into text
Browse files Browse the repository at this point in the history
  • Loading branch information
JieningYu committed Oct 6, 2023
2 parents 5e68e0f + 8108c48 commit 5400b1b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 62 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/clippy-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: clippy-review
on: [pull_request]
jobs:
clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: giraffate/clippy-action@v1
with:
reporter: 'github-pr-review'
8 changes: 4 additions & 4 deletions primitives/src/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static NAMESPACE_CACHES: once_cell::sync::Lazy<rimecraft_caches::Caches<String>>
#[derive(PartialEq, Eq, Clone, Hash, Debug)]
pub struct Identifier {
#[cfg(feature = "caches")]
namespace: crate::reference::PartialEqRef<'static, String>,
namespace: &'static str,

#[cfg(not(feature = "caches"))]
namespace: String,
Expand Down Expand Up @@ -46,7 +46,7 @@ impl Identifier {
}

Ok(Self {
namespace: NAMESPACE_CACHES.get(namespace_owned).into(),
namespace: NAMESPACE_CACHES.get(namespace_owned).as_str(),
path,
})
} else {
Expand Down Expand Up @@ -134,7 +134,7 @@ impl Identifier {
#[inline]
pub fn namespace(&self) -> &str {
#[cfg(feature = "caches")]
return self.namespace.0 .0;
return self.namespace;

#[cfg(not(feature = "caches"))]
return &self.namespace;
Expand All @@ -160,7 +160,7 @@ impl std::fmt::Display for Identifier {
#[inline]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
#[cfg(feature = "caches")]
return write!(f, "{}:{}", &*self.namespace, self.path);
return write!(f, "{}:{}", self.namespace, self.path);

#[cfg(not(feature = "caches"))]
return write!(f, "{}:{}", self.namespace, self.path);
Expand Down
58 changes: 0 additions & 58 deletions primitives/src/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,61 +58,3 @@ impl<'a, T: 'a> Hash for Reference<'a, T> {
(self.0 as *const T as usize).hash(state)
}
}

#[derive(Debug)]
#[repr(transparent)]
pub struct PartialEqRef<'a, T: ?Sized>(pub crate::Ref<'a, T>);

impl<'a, T: 'a + ?Sized> Copy for PartialEqRef<'a, T> {}

impl<'a, T: 'a + ?Sized> Clone for PartialEqRef<'a, T> {
#[inline]
fn clone(&self) -> Self {
*self
}
}

impl<'a, T: 'a + ?Sized> Deref for PartialEqRef<'a, T> {
type Target = T;

#[inline]
fn deref(&self) -> &Self::Target {
self.0 .0
}
}

impl<T> From<T> for PartialEqRef<'static, T> {
#[inline]
fn from(value: T) -> Self {
Self(Reference(Box::leak(Box::new(value))))
}
}

impl<'a, T: 'a> From<&'a T> for PartialEqRef<'a, T> {
#[inline]
fn from(value: &'a T) -> Self {
Self(Reference(value))
}
}

impl<'a, T: 'a> Eq for PartialEqRef<'a, T> where T: ?Sized + PartialEq {}

impl<'a, T: 'a> PartialEq for PartialEqRef<'a, T>
where
T: ?Sized + PartialEq,
{
#[inline]
fn eq(&self, other: &Self) -> bool {
self.0 == other.0 || self.0 .0 == other.0 .0
}
}

impl<'a, T: 'a> Hash for PartialEqRef<'a, T>
where
T: Hash,
{
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
self.0 .0.hash(state)
}
}

0 comments on commit 5400b1b

Please sign in to comment.