mod equality;
pub mod serde_dif;
pub mod unresolved_value_classification;
use crate::{
prelude::*, shared_values::PointerAddress, types::entity_type::EntityType,
};
#[derive(Debug, Clone, PartialEq, Eq, Default, Hash)]
pub struct ValueTag {
pub name: String,
pub is_empty: bool,
}
impl From<String> for ValueTag {
fn from(tag: String) -> Self {
ValueTag {
name: tag,
is_empty: false,
}
}
}
impl From<&str> for ValueTag {
fn from(tag: &str) -> Self {
ValueTag {
name: tag.to_string(),
is_empty: false,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Default, Hash)]
pub struct ValueClassification {
pub entity_type: Option<EntityType>,
pub impls: Vec<PointerAddress>,
pub tag: Option<ValueTag>,
}
impl ValueClassification {
pub fn new_unclassified() -> Self {
ValueClassification::default()
}
pub fn new_with_entity(entity: EntityType) -> Self {
ValueClassification {
entity_type: Some(entity),
..Default::default()
}
}
pub fn new_with_impls(impls: Vec<PointerAddress>) -> Self {
ValueClassification {
impls,
..Default::default()
}
}
pub fn new_with_tag(tag: impl Into<ValueTag>) -> Self {
ValueClassification {
tag: Some(tag.into()),
..Default::default()
}
}
pub fn new_with_maybe_tag(tag: Option<impl Into<ValueTag>>) -> Self {
ValueClassification {
tag: tag.map(|t| t.into()),
..Default::default()
}
}
pub fn merge(&self, other: ValueClassification) -> ValueClassification {
let mut merged_impls = self.impls.clone();
merged_impls.extend(other.impls);
ValueClassification {
entity_type: self.entity_type.clone().or(other.entity_type),
impls: merged_impls,
tag: self.tag.clone().or(other.tag),
}
}
pub fn tag_str(&self) -> Option<&str> {
match &self.tag {
Some(value_tag) => Some(&value_tag.name),
None => None,
}
}
pub fn is_unclassified(&self) -> bool {
self.entity_type.is_none()
&& self.impls.is_empty()
&& self.tag.is_none()
}
}
impl From<EntityType> for ValueClassification {
fn from(entity_type: EntityType) -> Self {
ValueClassification {
entity_type: Some(entity_type),
..Default::default()
}
}
}
impl From<Option<EntityType>> for ValueClassification {
fn from(entity_type: Option<EntityType>) -> Self {
ValueClassification {
entity_type,
..Default::default()
}
}
}
impl From<Vec<PointerAddress>> for ValueClassification {
fn from(impls: Vec<PointerAddress>) -> Self {
ValueClassification::new_with_impls(impls)
}
}
impl From<String> for ValueClassification {
fn from(tag: String) -> Self {
ValueClassification::new_with_tag(tag)
}
}