splitter/string/info/
mod.rs

1
2#[cfg(any(feature = "impls"))]
3mod impls;
4
5#[cfg(feature = "infos")]
6mod infos;
7#[cfg(feature = "infos")]
8pub use infos::*;
9
10/// The trait for the elements yielded by the [`crate::StrSplitter`]
11/// 
12/// ### Example
13/// ```rust
14/// use splitter::StrInfo;
15/// 
16/// #[derive(Default)]
17/// struct SpanCtx(usize);
18/// 
19/// struct Span {
20///     start: usize,
21///     end: usize,
22/// }
23/// 
24/// impl<'a> StrInfo<'a> for Span {
25///     type Context = SpanCtx;
26/// 
27///     fn generate(ctx: &mut Self::Context, ts: &'a str) -> Self {
28///         let start = ctx.0;
29///         ctx.0 += ts.len();
30///         Self { start, end: ctx.0 }
31///     }
32/// }
33/// ```
34pub trait StrInfo<'a>: Sized {
35    /// The needed `Context` for the [`StrInfo`], to generate the correct values
36    type Context: Default;
37    
38    /// Generates the [`StrInfo`], based on the provided context an slice
39    fn generate(_: &mut Self::Context, _: &'a str) -> Self;
40}
41
42impl<'a> StrInfo<'a> for &'a str {
43    type Context = ();
44    #[inline]
45    fn generate(_: &mut Self::Context, ts: &'a str) -> Self {
46        ts
47    }
48}