Skip to main content

provenant/output_schema/
url.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Serialize, Deserialize, Debug, Clone)]
4pub struct OutputURL {
5    pub url: String,
6    pub start_line: u64,
7    pub end_line: u64,
8}
9
10impl From<&crate::models::OutputURL> for OutputURL {
11    fn from(value: &crate::models::OutputURL) -> Self {
12        Self {
13            url: value.url.clone(),
14            start_line: value.start_line.get() as u64,
15            end_line: value.end_line.get() as u64,
16        }
17    }
18}
19
20impl TryFrom<&OutputURL> for crate::models::OutputURL {
21    type Error = String;
22    fn try_from(value: &OutputURL) -> Result<Self, Self::Error> {
23        use crate::models::LineNumber;
24        let start_line = LineNumber::new(value.start_line as usize)
25            .ok_or_else(|| format!("invalid start_line: {}", value.start_line))?;
26        let end_line = LineNumber::new(value.end_line as usize)
27            .ok_or_else(|| format!("invalid end_line: {}", value.end_line))?;
28        Ok(Self {
29            url: value.url.clone(),
30            start_line,
31            end_line,
32        })
33    }
34}