pub struct Name { /* private fields */ }Expand description
Component providing a human-readable name for an entity.
Names are useful for:
- Debugging and logging
- Editor integration and scene hierarchies
- Scripting references (find entity by name)
- UI display
§Performance
Names use Rust’s String type internally. For performance-critical code,
consider using entity IDs directly rather than string lookups.
§Example
use goud_engine::ecs::components::Name;
let name = Name::new("Player");
assert_eq!(name.as_str(), "Player");
let mut name = Name::new("Enemy");
name.set("Boss");
assert_eq!(name.as_str(), "Boss");Implementations§
Source§impl Name
impl Name
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the name as a string slice.
§Example
use goud_engine::ecs::components::Name;
let name = Name::new("Player");
assert_eq!(name.as_str(), "Player");Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of the name in bytes.
§Example
use goud_engine::ecs::components::Name;
let name = Name::new("Test");
assert_eq!(name.len(), 4);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the name is empty.
§Example
use goud_engine::ecs::components::Name;
let name = Name::new("");
assert!(name.is_empty());
let name2 = Name::new("Player");
assert!(!name2.is_empty());Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Consumes the Name and returns the inner String.
§Example
use goud_engine::ecs::components::Name;
let name = Name::new("Player");
let string: String = name.into_string();
assert_eq!(string, "Player");Sourcepub fn contains(&self, pattern: &str) -> bool
pub fn contains(&self, pattern: &str) -> bool
Returns true if the name contains the given pattern.
§Example
use goud_engine::ecs::components::Name;
let name = Name::new("Player_01");
assert!(name.contains("Player"));
assert!(name.contains("01"));
assert!(!name.contains("Enemy"));Sourcepub fn starts_with(&self, prefix: &str) -> bool
pub fn starts_with(&self, prefix: &str) -> bool
Returns true if the name starts with the given prefix.
§Example
use goud_engine::ecs::components::Name;
let name = Name::new("Player_01");
assert!(name.starts_with("Player"));
assert!(!name.starts_with("Enemy"));Trait Implementations§
Source§impl<'de> Deserialize<'de> for Name
impl<'de> Deserialize<'de> for Name
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Name, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Name, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for Name
impl Serialize for Name
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Component for Name
impl Eq for Name
impl StructuralPartialEq for Name
Auto Trait Implementations§
impl Freeze for Name
impl RefUnwindSafe for Name
impl Send for Name
impl Sync for Name
impl Unpin for Name
impl UnsafeUnpin for Name
impl UnwindSafe for Name
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().