Skip to content

Commit

Permalink
feat(Component, UntypedComponent): impl Display & Debug, uses EntityV…
Browse files Browse the repository at this point in the history
…iew's impl
  • Loading branch information
Indra-db committed Jan 27, 2025
1 parent 01324a4 commit 5374925
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
15 changes: 13 additions & 2 deletions flecs_ecs/src/core/components/component.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Registering and working with components
use std::{marker::PhantomData, ops::Deref, os::raw::c_void, ptr};
use std::{fmt::Debug, fmt::Display, marker::PhantomData, ops::Deref, os::raw::c_void, ptr};

use crate::core::*;
#[cfg(feature = "flecs_meta")]
Expand All @@ -9,12 +9,23 @@ use crate::sys;

/// Component class.
/// Class used to register components and component metadata.
#[derive(Debug)]
pub struct Component<'a, T> {
pub base: UntypedComponent<'a>,
_marker: PhantomData<T>,
}

impl<'a, T> Display for Component<'a, T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.base.entity)
}
}

impl<'a, T> Debug for Component<'a, T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.base.entity)
}
}

impl<T> Clone for Component<'_, T> {
fn clone(&self) -> Self {
*self
Expand Down
19 changes: 17 additions & 2 deletions flecs_ecs/src/core/components/component_untyped.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
use std::ops::Deref;
use std::{
fmt::{Debug, Display},
ops::Deref,
};

use crate::core::*;

/// Untyped component class.
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy)]
pub struct UntypedComponent<'a> {
pub entity: EntityView<'a>,
}

impl Display for UntypedComponent<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.entity)
}
}

impl Debug for UntypedComponent<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.entity)
}
}

impl<'a> Deref for UntypedComponent<'a> {
type Target = EntityView<'a>;

Expand Down

0 comments on commit 5374925

Please sign in to comment.