Skip to main content

des_sim/source_handler/
view.rs

1//! The `view` module defines `SourceView`, a read-only representation of a
2//! simulation source.
3//!
4//! This view provides access to a source's unique ID and its name, allowing
5//! for identification and logging without exposing the mutable internal state
6//! or implementation details of the source itself.
7
8use crate::primitive::id::SourceId;
9use std::sync::Arc;
10
11/// A read-only view of a simulation source, providing access to its identity and name.
12#[derive(Debug)]
13pub struct SourceView {
14    source_id: SourceId,
15    name: Arc<str>,
16}
17
18impl SourceView {
19    /// Creates a new `SourceView`.
20    pub(crate) fn new(source_id: SourceId, name: Arc<str>) -> SourceView {
21        SourceView { source_id, name }
22    }
23
24    /// Returns the unique identifier of the source.
25    pub fn source_id(&self) -> SourceId {
26        self.source_id
27    }
28
29    /// Returns the name of the source as a string slice.
30    pub fn name(&self) -> &str {
31        self.name.as_ref()
32    }
33}