Skip to main content

cyanea_core/
traits.rs

1//! Core trait definitions for the Cyanea ecosystem.
2//!
3//! These traits define the contracts that domain types implement across crates.
4
5/// A biological sequence (DNA, RNA, protein, etc.).
6pub trait Sequence {
7    /// The raw byte representation of the sequence.
8    fn as_bytes(&self) -> &[u8];
9
10    /// Length in residues/bases.
11    fn len(&self) -> usize {
12        self.as_bytes().len()
13    }
14
15    /// Whether the sequence is empty.
16    fn is_empty(&self) -> bool {
17        self.as_bytes().is_empty()
18    }
19}
20
21/// A type whose identity can be derived from its content via cryptographic hash.
22pub trait ContentAddressable {
23    /// Return the content hash as a hex string (e.g. SHA-256).
24    fn content_hash(&self) -> String;
25}
26
27/// A type that can be compressed and decompressed.
28pub trait Compressible: Sized {
29    /// Compress to bytes.
30    fn compress(&self) -> crate::Result<Vec<u8>>;
31
32    /// Decompress from bytes.
33    fn decompress(data: &[u8]) -> crate::Result<Self>;
34}
35
36/// A type that carries a numeric score (alignment score, quality, etc.).
37pub trait Scored {
38    /// The score value.
39    fn score(&self) -> f64;
40}
41
42/// A type that carries annotations (names, descriptions, metadata).
43pub trait Annotated {
44    /// A human-readable name or identifier.
45    fn name(&self) -> &str;
46
47    /// An optional description.
48    fn description(&self) -> Option<&str> {
49        None
50    }
51}
52
53/// A type that can produce a summary of its contents.
54pub trait Summarizable {
55    /// A one-line summary suitable for display.
56    fn summary(&self) -> String;
57}