From 3696e9d3f16e418fefb1cac3d68a756f57d29767 Mon Sep 17 00:00:00 2001 From: figsoda Date: Sat, 18 Feb 2023 13:09:16 -0500 Subject: [PATCH] make `parse` more generic --- src/lib.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 79d7692..d223077 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,9 +39,11 @@ use chumsky::{ prelude::Simple, primitive::{choice, end, filter, just}, recursive::recursive, - Error, Parser, + Error, Parser, Stream, }; +use std::ops::Range; + use crate::macros::set; /// Python dependency specified by [PEP 508](https://peps.python.org/pep-0508) @@ -125,8 +127,15 @@ pub enum Comparator { } /// Parse a [PEP 508](https://peps.python.org/pep-0508) string into a [Dependency] -pub fn parse(s: &str) -> Result>> { - parser().then_ignore(end()).parse(s) +/// ``` +/// # use pep_508::parse; +/// assert_eq!(parse("requests >= 2").unwrap().name, "requests"); +/// assert_eq!(parse(String::from("numpy")).unwrap().name, "numpy"); +/// ``` +pub fn parse<'a, I: Iterator)> + 'a>( + dependency: impl Into, I>>, +) -> Result>> { + parser().then_ignore(end()).parse(dependency) } /// Create a [chumsky](https://docs.rs/chumsky) parser,