debian_watch/
types_v5.rs

1use crate::parse_v5::{EntryV5, WatchFileV5};
2use crate::traits::{WatchEntry, WatchFileFormat};
3use crate::types::ParseError;
4use crate::VersionPolicy;
5
6impl WatchFileFormat for WatchFileV5 {
7    type Entry = EntryV5;
8
9    fn version(&self) -> u32 {
10        self.version()
11    }
12
13    fn entries(&self) -> Box<dyn Iterator<Item = Self::Entry> + '_> {
14        Box::new(WatchFileV5::entries(self))
15    }
16
17    fn to_string(&self) -> String {
18        ToString::to_string(self)
19    }
20}
21
22impl WatchEntry for EntryV5 {
23    fn url(&self) -> String {
24        // In format 5, the URL is in the "Source" field
25        self.source().unwrap_or_default()
26    }
27
28    fn matching_pattern(&self) -> Option<String> {
29        self.matching_pattern_v5()
30    }
31
32    fn version_policy(&self) -> Result<Option<VersionPolicy>, ParseError> {
33        // Format 5 uses "Version-Policy" field
34        match self.get_option("Version-Policy") {
35            Some(policy) => Ok(Some(policy.parse()?)),
36            None => Ok(None),
37        }
38    }
39
40    fn script(&self) -> Option<String> {
41        // Format 5 uses "Script" field
42        self.get_option("Script")
43    }
44
45    fn get_option(&self, key: &str) -> Option<String> {
46        // Use the internal get_field method which handles normalization
47        self.get_field(key)
48    }
49
50    fn has_option(&self, key: &str) -> bool {
51        self.get_option(key).is_some()
52    }
53}