impl more traits for bevy_core::Name (#3611)
# Objective - `Name` component is missing some useful trait impls. ## Solution - Implement the missing traits. `Display`, `AsRef<str>`, and several other conversions to and from strings.
This commit is contained in:
		
							parent
							
								
									f00aec2454
								
							
						
					
					
						commit
						6b8d64cd01
					
				| @ -68,12 +68,48 @@ impl Name { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | impl std::fmt::Display for Name { | ||||||
|  |     #[inline(always)] | ||||||
|  |     fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||||||
|  |         std::fmt::Display::fmt(&self.name, f) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /* Conversions from strings */ | ||||||
|  | 
 | ||||||
| impl From<&str> for Name { | impl From<&str> for Name { | ||||||
|     #[inline(always)] |     #[inline(always)] | ||||||
|     fn from(name: &str) -> Self { |     fn from(name: &str) -> Self { | ||||||
|         Name::new(name.to_owned()) |         Name::new(name.to_owned()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | impl From<String> for Name { | ||||||
|  |     #[inline(always)] | ||||||
|  |     fn from(name: String) -> Self { | ||||||
|  |         Name::new(name) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /* Conversions to strings */ | ||||||
|  | 
 | ||||||
|  | impl AsRef<str> for Name { | ||||||
|  |     #[inline(always)] | ||||||
|  |     fn as_ref(&self) -> &str { | ||||||
|  |         &self.name | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | impl From<&Name> for String { | ||||||
|  |     #[inline(always)] | ||||||
|  |     fn from(val: &Name) -> String { | ||||||
|  |         val.as_str().to_owned() | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | impl From<Name> for String { | ||||||
|  |     #[inline(always)] | ||||||
|  |     fn from(val: Name) -> String { | ||||||
|  |         val.name.into_owned() | ||||||
|  |     } | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| impl Hash for Name { | impl Hash for Name { | ||||||
|     fn hash<H: Hasher>(&self, state: &mut H) { |     fn hash<H: Hasher>(&self, state: &mut H) { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 JoJoJet
						JoJoJet