Skip to main content

tilo_resource/
search_preview.rs

1//! The preview a search hit carries for the palette's preview band.
2
3/// What the palette's preview band shows of a hit: a heading, short facts
4/// side by side, items one per line and the start of its text. Data only; the
5/// platform lays it out.
6#[derive(Clone, Debug, Default, PartialEq, Eq)]
7pub struct SearchPreview {
8    pub title: Option<String>,
9    pub facts: Vec<String>,
10    pub lines: Vec<String>,
11    pub body: Option<String>,
12}
13
14impl SearchPreview {
15    /// A preview headed `title`.
16    #[must_use]
17    pub fn titled(title: impl Into<String>) -> Self {
18        Self {
19            title: Some(title.into()),
20            ..Self::default()
21        }
22    }
23
24    /// One more fact beside the others.
25    #[must_use]
26    pub fn fact(mut self, fact: impl Into<String>) -> Self {
27        self.facts.push(fact.into());
28        self
29    }
30
31    /// One more item line.
32    #[must_use]
33    pub fn line(mut self, line: impl Into<String>) -> Self {
34        self.lines.push(line.into());
35        self
36    }
37
38    /// The start of its text.
39    #[must_use]
40    pub fn body(mut self, body: impl Into<String>) -> Self {
41        self.body = Some(body.into());
42        self
43    }
44}