| 1 | # R DESCRIPTION parser |
| 2 | |
| 3 | This crate provides a parser and editor for the `DESCRIPTION` files used in R |
| 4 | packages. |
| 5 | |
| 6 | See <https://r-pkgs.org/description.html> and |
| 7 | <https://cran.r-project.org/doc/manuals/R-exts.html> for more information on |
| 8 | the format. |
| 9 | |
| 10 | Besides parsing the control files it also supports parsing and comparison |
| 11 | of version strings according to the R package versioning scheme as well |
| 12 | as relations between versions. |
| 13 | |
| 14 | ## Example |
| 15 | |
| 16 | ```rust |
| 17 | |
| 18 | use std::str::FromStr; |
| 19 | use r_description::lossy::RDescription; |
| 20 | |
| 21 | let mut desc = RDescription::from_str(r###"Package: foo |
| 22 | Version: 1.0 |
| 23 | Depends: R (>= 3.0.0) |
| 24 | Description: A foo package |
| 25 | Title: A foo package |
| 26 | License: GPL-3 |
| 27 | "###).unwrap(); |
| 28 | |
| 29 | assert_eq!(desc.name, "foo"); |
| 30 | assert_eq!(desc.version, "1.0".parse().unwrap()); |
| 31 | assert_eq!(desc.depends, Some("R (>= 3.0.0)".parse().unwrap())); |
| 32 | |
| 33 | desc.license = "MIT".to_string(); |
| 34 | ``` |
| 35 | |
| 36 | ```rust |
| 37 | use r_description::Version; |
| 38 | |
| 39 | // '-' and '.' are equivalent separators in R version strings |
| 40 | let v1: Version = "2.5-1".parse().unwrap(); |
| 41 | let v2: Version = "2.5.1".parse().unwrap(); |
| 42 | assert_eq!(v1, v2); |
| 43 | |
| 44 | // Version strings can have more than three components |
| 45 | let v1: Version = "1.2.3.9000".parse().unwrap(); |
| 46 | let v2: Version = "1.2.3".parse().unwrap(); |
| 47 | assert!(v1 > v2); |
| 48 | |
| 49 | ``` |
| 50 | |
| 51 | ```rust |
| 52 | use std::str::FromStr; |
| 53 | use r_description::lossy::Relations; |
| 54 | |
| 55 | let v1 = r_description::Version::from_str("1.2.3").unwrap(); |
| 56 | let rels: Relations = "cli (>= 2.0), crayon (== 1.3.4), testthat".parse().unwrap(); |
| 57 | assert_eq!(3, rels.len()); |
| 58 | assert_eq!(rels[0].name, "cli"); |
| 59 | ``` |