 efda7f3f9c
			
		
	
	
		efda7f3f9c
		
			
		
	
	
	
	
		
			
			Takes the first two commits from #15375 and adds suggestions from this comment: https://github.com/bevyengine/bevy/pull/15375#issuecomment-2366968300 See #15375 for more reasoning/motivation. ## Rebasing (rerunning) ```rust git switch simpler-lint-fixes git reset --hard main cargo fmt --all -- --unstable-features --config normalize_comments=true,imports_granularity=Crate cargo fmt --all git add --update git commit --message "rustfmt" cargo clippy --workspace --all-targets --all-features --fix cargo fmt --all -- --unstable-features --config normalize_comments=true,imports_granularity=Crate cargo fmt --all git add --update git commit --message "clippy" git cherry-pick e6c0b94f6795222310fb812fa5c4512661fc7887 ```
		
			
				
	
	
		
			39 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| use syn::{
 | |
|     parse::{Parse, ParseStream, Peek},
 | |
|     punctuated::Punctuated,
 | |
| };
 | |
| 
 | |
| /// Returns a [`syn::parse::Parser`] which parses a stream of zero or more occurrences of `T`
 | |
| /// separated by punctuation of type `P`, with optional trailing punctuation.
 | |
| ///
 | |
| /// This is functionally the same as [`Punctuated::parse_terminated`],
 | |
| /// but accepts a closure rather than a function pointer.
 | |
| pub(crate) fn terminated_parser<T, P, F: FnMut(ParseStream) -> syn::Result<T>>(
 | |
|     terminator: P,
 | |
|     mut parser: F,
 | |
| ) -> impl FnOnce(ParseStream) -> syn::Result<Punctuated<T, P::Token>>
 | |
| where
 | |
|     P: Peek,
 | |
|     P::Token: Parse,
 | |
| {
 | |
|     let _ = terminator;
 | |
|     move |stream: ParseStream| {
 | |
|         let mut punctuated = Punctuated::new();
 | |
| 
 | |
|         loop {
 | |
|             if stream.is_empty() {
 | |
|                 break;
 | |
|             }
 | |
|             let value = parser(stream)?;
 | |
|             punctuated.push_value(value);
 | |
|             if stream.is_empty() {
 | |
|                 break;
 | |
|             }
 | |
|             let punct = stream.parse()?;
 | |
|             punctuated.push_punct(punct);
 | |
|         }
 | |
| 
 | |
|         Ok(punctuated)
 | |
|     }
 | |
| }
 |