vectorclip 0.1.0

Simple crate to get a part of a vector
Documentation
#[cfg(test)]
mod tests {

    use super::*;
    #[test]
    fn clip_test() -> Result<(), &'static str> {
        let vector: Vec<u8> = vec![5,10,15,20,25,30,35,40,45];
        println!("{:?}", clip(vector,1, 3)?);
        Ok(())
    }
}

/// # Clip
///
/// Function to get a part of a vector
///
/// ## Examples
///
/// ```rs
/// let vector: Vec<u8> = vec![5,10,15,20,25,30,35,40,45];
/// let clipped: Vec<u8> = clip(vector,1, 3)?;
/// println!("{}", clipped[0]); // 10
/// ```
pub fn clip<'a, T: Copy>(vector: Vec<T>, start: usize, end: usize) -> Result<Vec<T>, &'a str>{
    if start < 0 {
        return Err("Starting index has to be 0 or more");
    }
    if end >= vector.len() {
        return Err("Ending index has to be less than vector length");
    }
    let mut clipped : Vec<T> = vec![];
    for i in start..end {
        clipped.push(vector[i]);
    }
    Ok(clipped)
}