Skip to main content

relay_knowledge/domain/core/
source.rs

1use serde::{Deserialize, Serialize};
2
3use super::{DomainError, error::required_text};
4
5/// Authorized source boundary for evidence and retrieval.
6#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
7pub struct SourceScope(String);
8
9impl SourceScope {
10    /// Validates a source scope supplied by an interface adapter.
11    pub fn parse(value: impl Into<String>) -> Result<Self, DomainError> {
12        let scope = required_text("source_scope", value)?;
13        if scope.contains('\0') {
14            return Err(DomainError::invalid(
15                "source_scope",
16                "must not contain NUL bytes",
17            ));
18        }
19
20        Ok(Self(scope))
21    }
22
23    /// Returns the normalized scope identifier.
24    pub fn as_str(&self) -> &str {
25        &self.0
26    }
27}
28
29impl From<SourceScope> for String {
30    fn from(scope: SourceScope) -> Self {
31        scope.0
32    }
33}
34
35#[cfg(test)]
36#[path = "source_tests.rs"]
37mod tests;