icu_pattern 
icu_pattern
is a utility crate of the ICU4X
project.
It includes a [Pattern
] struct which wraps a paid of [Parser
] and [Interpolator
] allowing for parsing and interpolation of ICU placeholder patterns, like "{0} days" or
"{0}, {1}" with custom elements and string literals.
Placeholders & Elements
The [Parser
] is generic over any Placeholder
which implements FromStr
allowing the consumer to parse placeholder patterns such as "{0}, {1}",
"{date}, {time}" or any other.
The [Interpolator
] can interpolate the [Pattern
] against any
iterator over Element
.
Examples
In the following example we're going to use a custom Token
type,
and an Element
type which will be either a Token
or a string slice.
For the purpose of the example, a higher level
interpolate_to_string
method
is being used.
use Pattern;
use ;
let pattern: =
"{0}, {1}".try_into.expect;
let replacements = vec!;
assert_eq!;
Combinators
In the example above, the replacements will be parsed at compile time and stored on a [Vec
],
which is a collection type that has an implementation for [ReplacementProvider
]
trait.
In real use, the consumer may want to use different models of replacement provider, and different element schemas. Because the replacement is an iterator itself, it allows for other, more specialized parsers, to be used to lazily parse particular patterns that are meant to replace the placeholders. This allows for lazy parsing of those specialized patterns to be triggered only if the placeholder pattern encounters a placeholder key that requires given pattern to be used.
More Information
For more information on development, authorship, contributing etc. please visit ICU4X home page
.