Skip to main content

sealed_surface/
host.rs

1//! What the host is allowed to put in HTML / clipboard.
2
3/// One host-visible string. Must not be a cell datum in sealed mode.
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct HostText {
6    /// Role for audits (`caption`, `inspect`).
7    pub kind: &'static str,
8    /// Unicode the host may emit.
9    pub text: String,
10}
11
12/// Clipboard payload produced only in copyable mode.
13#[derive(Debug, Clone, PartialEq, Eq)]
14#[non_exhaustive]
15pub enum ClipboardPayload {
16    /// Nothing.
17    None,
18    /// Tab-separated viewport including headers.
19    Tsv(String),
20}
21
22impl ClipboardPayload {
23    /// True when no Unicode dump is offered.
24    #[must_use]
25    pub const fn is_none(&self) -> bool {
26        matches!(self, Self::None)
27    }
28}
29
30/// Leak surface. Contract tests serialize this, not the pixmap.
31#[derive(Debug, Clone, PartialEq, Eq)]
32#[non_exhaustive]
33pub struct HostProjection {
34    /// Strings the host may place in the DOM / ARIA.
35    pub text_nodes: Vec<HostText>,
36    /// Clipboard. [`ClipboardPayload::None`] when sealed.
37    pub clipboard: Option<ClipboardPayload>,
38}
39
40impl HostProjection {
41    pub(crate) fn sealed() -> Self {
42        Self {
43            text_nodes: Vec::new(),
44            clipboard: None,
45        }
46    }
47
48    /// Concatenate host text + clipboard for grep tests.
49    #[must_use]
50    pub fn audit_text(&self) -> String {
51        let mut s = String::new();
52        for t in &self.text_nodes {
53            s.push_str(&t.text);
54            s.push('\n');
55        }
56        if let Some(ClipboardPayload::Tsv(tsv)) = &self.clipboard {
57            s.push_str(tsv);
58        }
59        s
60    }
61}