1 // This file is part of ICU4X. For terms of use, please see the file 2 // called LICENSE at the top level of the ICU4X source tree 3 // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). 4 5 #[diplomat::bridge] 6 #[diplomat::abi_rename = "icu4x_{0}_mv1"] 7 #[diplomat::attr(auto, namespace = "icu4x")] 8 pub mod ffi { 9 use alloc::boxed::Box; 10 use core::ops::RangeInclusive; 11 12 /// Result of a single iteration of [`CodePointRangeIterator`]. 13 /// Logically can be considered to be an `Option<RangeInclusive<DiplomatChar>>`, 14 /// 15 /// `start` and `end` represent an inclusive range of code points [start, end], 16 /// and `done` will be true if the iterator has already finished. The last contentful 17 /// iteration will NOT produce a range done=true, in other words `start` and `end` are useful 18 /// values if and only if `done=false`. 19 #[diplomat::out] 20 pub struct CodePointRangeIteratorResult { 21 pub start: DiplomatChar, 22 pub end: DiplomatChar, 23 pub done: bool, 24 } 25 26 /// An iterator over code point ranges, produced by `CodePointSetData` or 27 /// one of the `CodePointMapData` types 28 #[diplomat::opaque] 29 pub struct CodePointRangeIterator<'a>( 30 pub Box<dyn Iterator<Item = RangeInclusive<DiplomatChar>> + 'a>, 31 ); 32 33 impl<'a> CodePointRangeIterator<'a> { 34 /// Advance the iterator by one and return the next range. 35 /// 36 /// If the iterator is out of items, `done` will be true next(&mut self) -> CodePointRangeIteratorResult37 pub fn next(&mut self) -> CodePointRangeIteratorResult { 38 self.0 39 .next() 40 .map(|r| CodePointRangeIteratorResult { 41 start: *r.start(), 42 end: *r.end(), 43 done: false, 44 }) 45 .unwrap_or(CodePointRangeIteratorResult { 46 start: 0, 47 end: 0, 48 done: true, 49 }) 50 } 51 } 52 } 53