pdfium_render/pdf/path/
segments.rs1use crate::bindings::PdfiumLibraryBindings;
5use crate::error::PdfiumError;
6use crate::pdf::path::segment::PdfPathSegment;
7use std::ops::{Range, RangeInclusive};
8
9pub type PdfPathSegmentIndex = u32;
11
12pub trait PdfPathSegments<'a> {
15 fn bindings(&self) -> &'a dyn PdfiumLibraryBindings;
17
18 fn len(&self) -> PdfPathSegmentIndex;
20
21 #[inline]
23 fn is_empty(&self) -> bool {
24 self.len() == 0
25 }
26
27 #[inline]
29 fn as_range(&self) -> Range<PdfPathSegmentIndex> {
30 0..self.len()
31 }
32
33 #[inline]
35 fn as_range_inclusive(&self) -> RangeInclusive<PdfPathSegmentIndex> {
36 if self.is_empty() { 0..=0 } else { 0..=(self.len() - 1) }
37 }
38
39 fn get(&self, index: PdfPathSegmentIndex) -> Result<PdfPathSegment<'a>, PdfiumError>;
41
42 fn iter(&'a self) -> PdfPathSegmentsIterator<'a>;
44}
45
46pub struct PdfPathSegmentsIterator<'a> {
48 segments: &'a dyn PdfPathSegments<'a>,
49 next_index: PdfPathSegmentIndex,
50}
51
52impl<'a> PdfPathSegmentsIterator<'a> {
53 #[inline]
54 pub(crate) fn new(segments: &'a dyn PdfPathSegments<'a>) -> Self {
55 PdfPathSegmentsIterator {
56 segments,
57 next_index: 0,
58 }
59 }
60}
61
62impl<'a> Iterator for PdfPathSegmentsIterator<'a> {
63 type Item = PdfPathSegment<'a>;
64
65 fn next(&mut self) -> Option<Self::Item> {
66 let next = self.segments.get(self.next_index);
67
68 self.next_index += 1;
69
70 next.ok()
71 }
72}