Skip to main content

detect_version

Function detect_version 

Source
pub fn detect_version(content: &str) -> Option<WatchFileVersion>
Expand description

Detect the version/format of a watch file from its content

This function examines the content to determine if it’s a line-based format (v1-4) or deb822 format (v5).

After detecting the version, you can either:

  • Use the parse() function to automatically parse and return a ParsedWatchFile
  • Parse directly: content.parse::<debian_watch::linebased::WatchFile>()

§Examples

use debian_watch::parse::{detect_version, WatchFileVersion};

let v4_content = "version=4\nhttps://example.com/ .*.tar.gz";
assert_eq!(detect_version(v4_content), Some(WatchFileVersion::LineBased(4)));

let v5_content = "Version: 5\n\nSource: https://example.com/";
assert_eq!(detect_version(v5_content), Some(WatchFileVersion::Deb822));