-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request '1.21.1 Migration' (#50) from 1.21.1migration into…
… main Reviewed-on: https://codeberg.org/DM-Earth/rimecraft/pulls/50 Reviewed-by: C191239 <[email protected]>
- Loading branch information
Showing
17 changed files
with
1,024 additions
and
605 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use std::fmt::Debug; | ||
|
||
use ahash::AHashSet; | ||
use component::{map::ComponentMap, ComponentType, RawErasedComponentType}; | ||
use rimecraft_global_cx::ProvideIdTy; | ||
|
||
/// Access to components of a block entity. | ||
pub struct ComponentsAccess<'env, 'a, Cx> | ||
where | ||
Cx: ProvideIdTy, | ||
{ | ||
pub(crate) set: &'env mut AHashSet<RawErasedComponentType<'a, Cx>>, | ||
pub(crate) map: &'env ComponentMap<'a, Cx>, | ||
} | ||
|
||
impl<'a, Cx> ComponentsAccess<'_, 'a, Cx> | ||
where | ||
Cx: ProvideIdTy, | ||
{ | ||
/// Gets a component of the given type. | ||
/// | ||
/// # Safety | ||
/// | ||
/// This function could not guarantee lifetime of type `T` is sound. | ||
/// The type `T`'s lifetime parameters should not overlap lifetime `'a`. | ||
pub unsafe fn get<T>(&mut self, ty: &ComponentType<'a, T>) -> Option<&T> { | ||
self.set.insert(RawErasedComponentType::from(ty)); | ||
self.map.get(ty) | ||
} | ||
|
||
/// Reborrow this access. | ||
pub fn reborrow(&mut self) -> ComponentsAccess<'_, 'a, Cx> { | ||
ComponentsAccess { | ||
set: self.set, | ||
map: self.map, | ||
} | ||
} | ||
} | ||
|
||
impl<Cx> Debug for ComponentsAccess<'_, '_, Cx> | ||
where | ||
Cx: ProvideIdTy<Id: Debug> + Debug, | ||
{ | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.debug_struct("ComponentsAccess") | ||
.field("set", &self.set) | ||
.field("map", &self.map) | ||
.finish() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.