Skip to content

Commit

Permalink
Changed &String to &str to avoid making excess strings
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyTornetta committed Oct 30, 2023
1 parent 51b3592 commit 620ebee
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions cosmos_client/src/lang/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl<T: Identifiable + Send + Sync> Lang<T> {
/// Gets the text for this specific entry
///
/// Make sure `register(item)` was called first!
pub fn get_name(&self, item: &T) -> Option<&String> {
pub fn get_name(&self, item: &T) -> Option<&str> {
self.get_name_from_numeric_id(item.id())
}

Expand All @@ -93,8 +93,8 @@ impl<T: Identifiable + Send + Sync> Lang<T> {
/// Gets the text for this specific numerical id.
///
/// Make sure `register(item)` was called first!
pub fn get_name_from_numeric_id(&self, id: u16) -> Option<&String> {
self.map.get(&id)
pub fn get_name_from_numeric_id(&self, id: u16) -> Option<&str> {
self.map.get(&id).map(|x| x.as_str())
}
}

Expand Down
2 changes: 1 addition & 1 deletion cosmos_client/src/ui/hotbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fn listen_for_change_events(
if let Some(is) = inv.itemstack_at(hb.selected_slot()) {
name_text.sections[0].value = names
.get_name_from_numeric_id(is.item_id())
.unwrap_or(&items.from_numeric_id(is.item_id()).unlocalized_name().to_string())
.unwrap_or(items.from_numeric_id(is.item_id()).unlocalized_name())
.to_owned();

name_text.sections[0].style.color = Color::WHITE;
Expand Down

0 comments on commit 620ebee

Please sign in to comment.