eryon-mem 0.0.4

this crate implements the memory-related aspects of the eryon framework
/*
    appellation: impl_relationship <module>
    authors: @FL03
*/
use super::{FeatureRelationship, RelationshipType};

impl<T> FeatureRelationship<T> {
    /// returns a new [`FeatureRelationship`] with the given parameters
    pub const fn new(
        source_id: usize,
        to_id: usize,
        relationship_type: RelationshipType,
        strength: T,
    ) -> Self {
        Self {
            source_id,
            to_id,
            relationship_type,
            strength,
            occurrences: 1,
        }
    }
    /// returns a reference to the source feature ID
    pub const fn from_id(&self) -> usize {
        self.source_id
    }
    /// returns a mutable reference to the source feature ID
    pub const fn from_id_mut(&mut self) -> &mut usize {
        &mut self.source_id
    }
    /// returns a reference to the target feature ID
    pub const fn to_id(&self) -> usize {
        self.to_id
    }
    /// returns a mutable reference to the target feature ID
    pub const fn to_id_mut(&mut self) -> &mut usize {
        &mut self.to_id
    }
    /// returns a copy of the number of occurrences
    pub const fn occurrences(&self) -> usize {
        self.occurrences
    }
    /// returns a mutable reference to the number of occurrences
    pub const fn occurrences_mut(&mut self) -> &mut usize {
        &mut self.occurrences
    }
    /// returns a reference to the type of relationship
    pub const fn relationship_type(&self) -> &RelationshipType {
        &self.relationship_type
    }
    /// returns a mutable reference to the type of relationship
    pub const fn relationship_type_mut(&mut self) -> &mut RelationshipType {
        &mut self.relationship_type
    }
    /// returns a reference to the strength of the relationship
    pub const fn strength(&self) -> &T {
        &self.strength
    }
    /// returns a mutable reference to the strength of the relationship
    pub const fn strength_mut(&mut self) -> &mut T {
        &mut self.strength
    }
    /// update the from_id and return a mutable reference to the replationship
    pub fn set_from_id(&mut self, from_id: usize) -> &mut Self {
        self.source_id = from_id;
        self
    }
    /// update the to_id and return a mutable reference to the replationship
    pub fn set_to_id(&mut self, to_id: usize) -> &mut Self {
        self.to_id = to_id;
        self
    }
    /// update the number of occurrences and return a mutable reference to the replationship
    pub fn set_occurrences(&mut self, occurrences: usize) -> &mut Self {
        self.occurrences = occurrences;
        self
    }
    /// update the relationship type and return a mutable reference to the replationship
    pub fn set_relationship_type(&mut self, relationship_type: RelationshipType) -> &mut Self {
        self.relationship_type = relationship_type;
        self
    }
    /// update the strength and return a mutable reference to the replationship
    pub fn set_strength(&mut self, strength: T) -> &mut Self {
        self.strength = strength;
        self
    }
    /// increment the number of occurrences by one
    pub fn increment_occurrences(&mut self) -> &mut Self {
        self.occurrences += 1;
        self
    }
    /// consumes the current instance to create another with the given from_id
    pub fn with_from_id(self, source_id: usize) -> Self {
        Self { source_id, ..self }
    }
    /// consumes the current instance to create another with the given to_id
    pub fn with_to_id(self, to_id: usize) -> Self {
        Self { to_id, ..self }
    }
    /// consumes the current instance to create another with the given occurrences
    pub fn with_occurrences(self, occurrences: usize) -> Self {
        Self {
            occurrences,
            ..self
        }
    }
    /// consumes the current instance to create another with the given relationship_type
    pub fn with_relationship_type(self, relationship_type: RelationshipType) -> Self {
        Self {
            relationship_type,
            ..self
        }
    }
    /// consumes the current instance to create another with the given strength
    pub fn with_strength(self, strength: T) -> Self {
        Self { strength, ..self }
    }
}