cloudfront_logs/raw/line/
checked.rs

1use crate::shared::*;
2
3#[derive(Debug, PartialEq, Clone, Copy)]
4pub struct LogLine<'a> {
5    pub date: &'a str,
6    pub time: &'a str,
7    pub x_edge_location: &'a str,
8    pub sc_bytes: &'a str,
9    pub c_ip: &'a str,
10    pub cs_method: &'a str,
11    pub cs_host: &'a str,
12    pub cs_uri_stem: &'a str,
13    pub sc_status: &'a str,
14    pub cs_referer: &'a str,
15    pub cs_user_agent: &'a str,
16    pub cs_uri_query: &'a str,
17    pub cs_cookie: &'a str,
18    pub x_edge_result_type: &'a str,
19    pub x_edge_request_id: &'a str,
20    pub x_host_header: &'a str,
21    pub cs_protocol: &'a str,
22    pub cs_bytes: &'a str,
23    pub time_taken: &'a str,
24    pub x_forwarded_for: &'a str,
25    pub ssl_protocol: &'a str,
26    pub ssl_cipher: &'a str,
27    pub x_edge_response_result_type: &'a str,
28    pub cs_protocol_version: &'a str,
29    pub fle_status: &'a str,
30    pub fle_encrypted_fields: &'a str,
31    pub c_port: &'a str,
32    pub time_to_first_byte: &'a str,
33    pub x_edge_detailed_result_type: &'a str,
34    pub sc_content_type: &'a str,
35    pub sc_content_len: &'a str,
36    pub sc_range_start: &'a str,
37    pub sc_range_end: &'a str,
38}
39
40impl<'a> TryFrom<&'a str> for LogLine<'a> {
41    type Error = &'static str;
42
43    fn try_from(line: &'a str) -> Result<Self, Self::Error> {
44        validate_line(line)?;
45
46        let mut iter = MemchrTabSplitter::new(line);
47
48        Ok(Self {
49            date: iter.next().unwrap(),
50            time: iter.next().unwrap(),
51            x_edge_location: iter.next().unwrap(),
52            sc_bytes: iter.next().unwrap(),
53            c_ip: iter.next().unwrap(),
54            cs_method: iter.next().unwrap(),
55            cs_host: iter.next().unwrap(),
56            cs_uri_stem: iter.next().unwrap(),
57            sc_status: iter.next().unwrap(),
58            cs_referer: iter.next().unwrap(),
59            cs_user_agent: iter.next().unwrap(),
60            cs_uri_query: iter.next().unwrap(),
61            cs_cookie: iter.next().unwrap(),
62            x_edge_result_type: iter.next().unwrap(),
63            x_edge_request_id: iter.next().unwrap(),
64            x_host_header: iter.next().unwrap(),
65            cs_protocol: iter.next().unwrap(),
66            cs_bytes: iter.next().unwrap(),
67            time_taken: iter.next().unwrap(),
68            x_forwarded_for: iter.next().unwrap(),
69            ssl_protocol: iter.next().unwrap(),
70            ssl_cipher: iter.next().unwrap(),
71            x_edge_response_result_type: iter.next().unwrap(),
72            cs_protocol_version: iter.next().unwrap(),
73            fle_status: iter.next().unwrap(),
74            fle_encrypted_fields: iter.next().unwrap(),
75            c_port: iter.next().unwrap(),
76            time_to_first_byte: iter.next().unwrap(),
77            x_edge_detailed_result_type: iter.next().unwrap(),
78            sc_content_type: iter.next().unwrap(),
79            sc_content_len: iter.next().unwrap(),
80            sc_range_start: iter.next().unwrap(),
81            sc_range_end: iter.next().unwrap(),
82        })
83    }
84}