Skip to content

Commit

Permalink
ref test
Browse files Browse the repository at this point in the history
  • Loading branch information
JieningYu committed Aug 10, 2023
1 parent c8cddaa commit 252b703
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
16 changes: 16 additions & 0 deletions src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,22 @@ impl<'a, T: 'a> Hash for Ref<'a, T> {
}
}

#[cfg(test)]
mod ref_tests {
use super::Ref;

#[test]
fn aligned() {
let string = "Hello, world!";
let str_ref = Ref(string);

assert_eq!(
unsafe { &*(&str_ref as *const Ref<str> as *const &'static str) },
&string
);
}
}

/// A static instance that can be created with a type in a [`std::sync::Mutex`]
/// to be mutable and be freezed into (maybe) another type inside a once cell.
/// Which the freezed instance can be accessed without a lock and be borrowed
Expand Down
5 changes: 2 additions & 3 deletions src/world/biome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ pub struct Weather {

pub type TemperatureModifier = (&'static str, fn(BlockPos, f32) -> f32);

#[derive(Clone, Copy, PartialEq, Eq)]
pub struct Shared<'w>(pub crate::Ref<'w, crate::registry::Entry<Biome>>);
pub type Shared<'w> = crate::Ref<'w, crate::registry::Entry<Biome>>;

pub struct SharedRegistry<'w>(pub crate::Ref<'w, crate::registry::Registry<Biome>>);

impl<'w> Indexed<Shared<'w>> for SharedRegistry<'w> {
fn get_raw_id(&self, value: &Shared<'w>) -> Option<usize> {
self.0.iter().position(|entry| crate::Ref(entry) == value.0)
self.0.iter().position(|entry| crate::Ref(entry) == *value)
}

fn get(&self, index: usize) -> Option<&Shared<'w>> {
Expand Down
2 changes: 1 addition & 1 deletion src/world/palette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<'a, T: 'a + PartialEq + Eq + Copy> Palette<'a, T> {
{
match &mut self.inner {
Inner::Vector(vec) => {
vec.clear();
*vec = Vec::new();

for _ in 0..crate::VarInt::decode(buf)? {
vec.push(
Expand Down

0 comments on commit 252b703

Please sign in to comment.