string_offsets/config.rs
1//! Configuration types for enabling/disabling features are compile time.
2//!
3//! By disabling features, the compiler can generate faster code which can be important for certain use cases.
4//! Certain implementations/conversion operations will only be available if the corresponding features were enabled.
5
6/// Type-level boolean.
7pub trait Bool {
8 /// The value of the boolean.
9 const VALUE: bool;
10}
11/// Type-level true.
12pub struct True {}
13/// Type-level false.
14pub struct False {}
15impl Bool for True {
16 const VALUE: bool = true;
17}
18impl Bool for False {
19 const VALUE: bool = false;
20}
21
22/// Configures which features should be enabled for a [`StringOffsets`] instance.
23pub trait ConfigType {
24 /// Whether to enable character conversions.
25 type HasChars: Bool;
26 /// Whether to enable UTF-16 conversions.
27 type HasUtf16: Bool;
28 /// Whether to enable line conversions.
29 type HasLines: Bool;
30 /// Whether to enable whitespace checks.
31 type HasWhitespace: Bool;
32}
33
34/// Configuration type that enables all features.
35pub struct AllConfig {}
36impl ConfigType for AllConfig {
37 type HasChars = True;
38 type HasUtf16 = True;
39 type HasLines = True;
40 type HasWhitespace = True;
41}
42
43/// Configuration type that only enables line conversions.
44pub struct OnlyLines {}
45impl ConfigType for OnlyLines {
46 type HasChars = False;
47 type HasUtf16 = False;
48 type HasLines = True;
49 type HasWhitespace = False;
50}