hyperlit_model/
segment.rs

1use crate::last_modification_info::LastModificationInfo;
2use crate::location::Location;
3
4pub type SegmentId = u32;
5
6#[derive(Debug, Clone, PartialEq)]
7pub struct Segment {
8    /// document-wide unique identifier
9    pub id: SegmentId,
10    /// title of this segment
11    pub title: String,
12    /// tags of this segment
13    pub tags: Vec<String>,
14    /// content text of this segment - may be markdown formatted
15    pub text: String,
16    /// location of this segment
17    pub location: Location,
18    /// whether the segment is already included in the output
19    pub location_url: Option<String>,
20    /// url of this location (e.g. in github, etc)
21    pub is_included: bool,
22    /// last modification info, usually from git
23    pub last_modification: LastModificationInfo,
24}
25
26impl Segment {
27    pub fn new(
28        id: SegmentId,
29        title: impl Into<String>,
30        tags: Vec<String>,
31        text: impl Into<String>,
32        location: Location,
33    ) -> Segment {
34        Segment {
35            id,
36            title: title.into(),
37            tags,
38            text: text.into(),
39            location,
40            is_included: false,
41            last_modification: LastModificationInfo::default(),
42            location_url: None,
43        }
44    }
45}
46
47pub fn segments_sort_by_title(segments: &mut [&Segment]) {
48    segments.sort_by(|a, b| a.title.cmp(&b.title));
49}