Enum icu::pattern::DoublePlaceholder
source · pub enum DoublePlaceholder {}
Expand description
Backend for patterns containing zero, one, or two placeholders.
This empty type is not constructible.
§Placeholder Keys
The placeholder is either DoublePlaceholderKey::Place0
or DoublePlaceholderKey::Place1
.
In Pattern::interpolate()
, pass a two-element array or tuple.
§Encoding Details
The first two code points contain the indices of the first and second placeholders with the following encoding:
- First bit: 0 for
DoublePlaceholderKey::Place0
, 1 forDoublePlaceholderKey::Place1
. - Second and higher bits: 1 plus the byte offset of the placeholder counting from after the placeholder index code points. If zero, skip this placeholder.
§Examples
Parsing a pattern into the encoding:
use core::str::FromStr;
use icu_pattern::DoublePlaceholder;
use icu_pattern::Pattern;
// Parse the string syntax and check the resulting data store:
let pattern = Pattern::<DoublePlaceholder>::try_from_str(
"Hello, {0} and {1}!",
Default::default(),
)
.unwrap();
assert_eq!("\x10\x1BHello, and !", &pattern.store);
Explanation of the lead code points:
\x10
is placeholder 0 at index 7: ((7 + 1) << 1) | 0\x1B
is placeholder 1 at index 12: ((12 + 1) << 1) | 1
Example patterns supported by this backend:
use core::str::FromStr;
use icu_pattern::DoublePlaceholder;
use icu_pattern::Pattern;
use icu_pattern::QuoteMode;
// Single numeric placeholder (note, "5" is used):
assert_eq!(
Pattern::<DoublePlaceholder>::try_from_str(
"{0} days ago",
Default::default()
)
.unwrap()
.interpolate_to_string([5, 7]),
"5 days ago",
);
// No placeholder (note, the placeholder value is never accessed):
assert_eq!(
Pattern::<DoublePlaceholder>::try_from_str(
"yesterday",
Default::default()
)
.unwrap()
.interpolate_to_string(["foo", "bar"]),
"yesterday",
);
// Escaped placeholder and a placeholder value 1 (note, "bar" is used):
assert_eq!(
Pattern::<DoublePlaceholder>::try_from_str(
"'{0}' {1}",
QuoteMode::QuotingSupported.into()
)
.unwrap()
.interpolate_to_string(("foo", "bar")),
"{0} bar",
);
// Pattern with the placeholders in the opposite order:
assert_eq!(
Pattern::<DoublePlaceholder>::try_from_str(
"A {1} B {0} C",
Default::default()
)
.unwrap()
.interpolate_to_string(("D", "E")),
"A E B D C",
);
// No literals, only placeholders:
assert_eq!(
Pattern::<DoublePlaceholder>::try_from_str(
"{1}{0}",
Default::default()
)
.unwrap()
.interpolate_to_string((1, "A")),
"A1",
);
Trait Implementations§
source§impl Clone for DoublePlaceholder
impl Clone for DoublePlaceholder
source§fn clone(&self) -> DoublePlaceholder
fn clone(&self) -> DoublePlaceholder
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for DoublePlaceholder
impl Debug for DoublePlaceholder
source§impl PartialEq for DoublePlaceholder
impl PartialEq for DoublePlaceholder
source§impl PatternBackend for DoublePlaceholder
impl PatternBackend for DoublePlaceholder
source§type PlaceholderKey<'a> = DoublePlaceholderKey
type PlaceholderKey<'a> = DoublePlaceholderKey
The type to be used as the placeholder key in code.
source§type PlaceholderKeyCow<'a> = DoublePlaceholderKey
type PlaceholderKeyCow<'a> = DoublePlaceholderKey
Cowable version of the type to be used as the placeholder key in code.
source§type Error<'a> = Infallible
type Error<'a> = Infallible
The type of error that the
TryWriteable
for this backend can return.impl Copy for DoublePlaceholder
impl Eq for DoublePlaceholder
impl StructuralPartialEq for DoublePlaceholder
Auto Trait Implementations§
impl Freeze for DoublePlaceholder
impl RefUnwindSafe for DoublePlaceholder
impl Send for DoublePlaceholder
impl Sync for DoublePlaceholder
impl Unpin for DoublePlaceholder
impl UnwindSafe for DoublePlaceholder
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more