unobtanium_segmenter/segmentation/
segmenter.rs

1use crate::SegmentedToken;
2use crate::UseOrSubdivide;
3
4/// Allows the segmenter to be part of a [SubdivisionMap][crate::SubdivisionMap] iterator and be chained using the [chain_segmenter][crate::chain::ChainSegmenter::chain_segmenter] methods.
5pub trait Segmenter {
6	/// The iterator type returned by the `subdivide` function if it has multiple results.
7	///
8	/// Setting this to `IntoIter<SegmentedToken<'a>>` for [std::vec::IntoIter] is a sane default. Allowing you to generate a valid iterator calling `into_iter()` on a Vec.
9	type SubdivisionIter<'a>: Iterator<Item = SegmentedToken<'a>>;
10
11	/// A method that should split the given `token` into zero, one or more subtokens.
12	///
13	/// Have a look at the [UseOrSubdivide] enum, which is similar to an [Option],
14	/// but can also return an owned iterator with multiple items in it.
15	fn subdivide<'a>(
16		&self,
17		token: SegmentedToken<'a>,
18	) -> UseOrSubdivide<SegmentedToken<'a>, Self::SubdivisionIter<'a>>;
19}