You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: segment_merge_iterator.rs
    path of file: ./repos/cursive/cursive-core/src/utils/lines/spans
    
    the code of the file until where you have to start completion: use super::Segment;

pub struct SegmentMergeIterator<I> {
    current: Option<Segment>,
    inner: I,
}

impl<I> SegmentMergeIterator<I> {
    pub fn new(inner: I) -> Self {
        SegmentMergeIterator {
            inner,
            current: None,
        }
    }
}

impl<I> I
    
    fn next(&mut self) -> Option<Self::Item> {
        // Always work on an segment.
        if self.current.is_none() {
            self.current = self.inner.next();
            self.current?;
        }

        // Keep growing our current segment until we find something else.
        loop {
            match self.inner.next() {
                None => return self.current.take(),
                Some(next) => {
                    if next.span_id == self.current.unwrap().span_id {
                        let current = self.current.as_mut().unwrap();
                        current.end = next.end;
                        current.width += next.width;
                    } else {
                        let current = self.current.take();
                        self.current = Some(next);
                        return current;
                    }
                }
            }
        }
    }