1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use summa_proto::proto;

use crate::proto_traits::Wrapper;

impl From<tantivy::Snippet> for Wrapper<proto::Snippet> {
    fn from(snippet: tantivy::Snippet) -> Self {
        Wrapper::from(proto::Snippet {
            fragment: snippet.fragment().as_bytes().to_vec(),
            highlights: snippet
                .highlighted()
                .iter()
                .map(|r| proto::Highlight {
                    from: r.start as u32,
                    to: r.end as u32,
                })
                .collect(),
            html: snippet.to_html(),
        })
    }
}