You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							40 lines
						
					
					
						
							835 B
						
					
					
				
			
		
		
	
	
							40 lines
						
					
					
						
							835 B
						
					
					
				use crate::utils::OneOrVec; | 
						|
use crate::UError; | 
						|
 | 
						|
pub struct CombinedResult<T, E = UError> { | 
						|
    ok: Vec<T>, | 
						|
    err: Vec<E>, | 
						|
} | 
						|
 | 
						|
impl<T, E> CombinedResult<T, E> { | 
						|
    pub fn new() -> Self { | 
						|
        Self { | 
						|
            ok: vec![], | 
						|
            err: vec![], | 
						|
        } | 
						|
    } | 
						|
 | 
						|
    pub fn ok<I: OneOrVec<T>>(&mut self, result: I) { | 
						|
        self.ok.extend(result.into_vec()); | 
						|
    } | 
						|
 | 
						|
    pub fn err<I: OneOrVec<E>>(&mut self, err: I) { | 
						|
        self.err.extend(err.into_vec()); | 
						|
    } | 
						|
 | 
						|
    pub fn unwrap(self) -> Vec<T> { | 
						|
        let err_len = self.err.len(); | 
						|
        if err_len > 0 { | 
						|
            panic!("CombinedResult has {} errors", err_len); | 
						|
        } | 
						|
        self.ok | 
						|
    } | 
						|
 | 
						|
    pub fn unwrap_one(self) -> T { | 
						|
        self.unwrap().pop().unwrap() | 
						|
    } | 
						|
 | 
						|
    pub fn pop_errors(&mut self) -> Vec<E> { | 
						|
        self.err.drain(..).collect() | 
						|
    } | 
						|
}
 | 
						|
 |