-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
147 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use syn::{ | ||
parse::{Parse, ParseStream}, | ||
token::Token, | ||
}; | ||
|
||
use super::*; | ||
|
||
/// Parse a metadata key-value pair, separated by `=`. | ||
pub fn parse_key_value<K: Token + Default + Parse, V: Parse>( | ||
input: ParseStream, | ||
) -> Result<Option<V>> { | ||
if !input.peek(|_| K::default()) { | ||
return Ok(None); | ||
} | ||
|
||
let _: K = input.parse()?; | ||
let _: syn::Token![=] = input.parse()?; | ||
let value: V = input.parse::<V>()?; | ||
eat_comma(input); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
Ok(Some(value)) | ||
} | ||
|
||
/// Parse a comma if there is one. | ||
pub fn eat_comma(input: ParseStream) { | ||
if input.peek(syn::Token![,]) { | ||
let _: syn::Token![,] = input.parse().unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Where would this comma even come from in our input?