mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 15:14:50 +00:00
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
1 changed files with 36 additions and 0 deletions
|
@ -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 {
|
||||
#[inline(always)]
|
||||
fn from(name: &str) -> Self {
|
||||
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 {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
|
|
Loading…
Reference in a new issue