diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2025-08-04 20:43:10 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-04 20:43:10 -0500 |
| commit | 23b7f20a0d88b54d430820baeb4a6da0316a009a (patch) | |
| tree | f3e780515b3bbb9973d2b94338be6194b5ec0af3 /azalea-inventory/src/default_components/mod.rs | |
| parent | 827d943c3f27c65724ff83689b40c87d1cd1838c (diff) | |
| download | azalea-drasl-23b7f20a0d88b54d430820baeb4a6da0316a009a.tar.xz | |
Default components (#232)
* add default components
* remove debug prints
* clippy
* use default components
* fix tests
Diffstat (limited to 'azalea-inventory/src/default_components/mod.rs')
| -rw-r--r-- | azalea-inventory/src/default_components/mod.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/azalea-inventory/src/default_components/mod.rs b/azalea-inventory/src/default_components/mod.rs new file mode 100644 index 00000000..e6150066 --- /dev/null +++ b/azalea-inventory/src/default_components/mod.rs @@ -0,0 +1,20 @@ +pub mod generated; + +use azalea_registry::Item; + +use crate::components::DataComponent; + +/// A [`DataComponent`] that some [`Item`]s may have a default value for. +pub trait DefaultableComponent: DataComponent { + fn default_for_item(item: Item) -> Option<Self> + where + Self: Sized; +} +impl<T: DataComponent> DefaultableComponent for T { + default fn default_for_item(_item: Item) -> Option<Self> { + None + } +} +pub fn get_default_component<T: DefaultableComponent>(item: Item) -> Option<T> { + T::default_for_item(item) +} |
