pub enum TypeLabel {
Core(EntityType),
Custom(String),
}Expand description
A unified type label supporting both core and custom entity types.
§Design Philosophy
Rather than having separate EntityType and String fields scattered
throughout the codebase, TypeLabel provides a single type that:
- Preserves type safety for known entity types via
EntityType - Allows extensibility for domain-specific types via
Custom - Provides consistent serialization (always as string)
- Enables bidirectional conversion with both
EntityTypeandString
§Serialization
TypeLabel serializes as a string for interoperability:
Core(EntityType::Person)→"PER"Custom("PROTEIN")→"PROTEIN"
Deserialization attempts to parse as EntityType first, falling back to Custom.
Variants§
Core(EntityType)
A core entity type from the canonical taxonomy.
Custom(String)
A custom domain-specific type not in the core taxonomy.
Implementations§
Source§impl TypeLabel
impl TypeLabel
Sourcepub fn custom(label: impl Into<String>) -> TypeLabel
pub fn custom(label: impl Into<String>) -> TypeLabel
Create a custom type label.
Note: if label matches a known EntityType label, this returns
TypeLabel::Core(...) instead. Use this to keep “custom means unknown”
consistent across parsing/serde roundtrips.
Sourcepub const fn as_core(&self) -> Option<&EntityType>
pub const fn as_core(&self) -> Option<&EntityType>
Try to get the core entity type, if this is one.
Sourcepub fn to_entity_type(&self) -> EntityType
pub fn to_entity_type(&self) -> EntityType
Convert to a core entity type, mapping customs to EntityType::Other.
Note: Custom types become EntityType::Other since we don’t have category info.
Use Self::to_entity_type_with_category if you have category information.
Sourcepub fn to_entity_type_with_category(
&self,
category: EntityCategory,
) -> EntityType
pub fn to_entity_type_with_category( &self, category: EntityCategory, ) -> EntityType
Convert to a core entity type with explicit category for customs.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for TypeLabel
impl<'de> Deserialize<'de> for TypeLabel
Source§fn deserialize<D>(
deserializer: D,
) -> Result<TypeLabel, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<TypeLabel, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl From<EntityType> for TypeLabel
impl From<EntityType> for TypeLabel
Source§fn from(et: EntityType) -> TypeLabel
fn from(et: EntityType) -> TypeLabel
Source§impl Serialize for TypeLabel
impl Serialize for TypeLabel
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,
impl Eq for TypeLabel
impl StructuralPartialEq for TypeLabel
Auto Trait Implementations§
impl Freeze for TypeLabel
impl RefUnwindSafe for TypeLabel
impl Send for TypeLabel
impl Sync for TypeLabel
impl Unpin for TypeLabel
impl UnsafeUnpin for TypeLabel
impl UnwindSafe for TypeLabel
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
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
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read moreSource§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.