Enum icu::pattern::SinglePlaceholder
source · pub enum SinglePlaceholder {}
Expand description
Backend for patterns containing zero or one placeholder.
This empty type is not constructible.
§Placeholder Keys
The placeholder is always SinglePlaceholderKey::Singleton
.
In Pattern::interpolate()
, pass a single-element array or tuple.
§Encoding Details
The first code point of the string is 1 plus the byte offset of the placeholder counting from after that initial code point. If zero, there is no placeholder.
§Examples
Parsing a pattern into the encoding:
use core::str::FromStr;
use icu_pattern::Pattern;
use icu_pattern::SinglePlaceholder;
// Parse the string syntax and check the resulting data store:
let pattern = Pattern::<SinglePlaceholder>::try_from_str(
"Hello, {0}!",
Default::default(),
)
.unwrap();
assert_eq!("\u{8}Hello, !", &pattern.store);
Example patterns supported by this backend:
use core::str::FromStr;
use icu_pattern::Pattern;
use icu_pattern::QuoteMode;
use icu_pattern::SinglePlaceholder;
// Single numeric placeholder:
assert_eq!(
Pattern::<SinglePlaceholder>::try_from_str(
"{0} days ago",
Default::default()
)
.unwrap()
.interpolate_to_string([5]),
"5 days ago",
);
// Single named placeholder:
assert_eq!(
Pattern::<SinglePlaceholder>::try_from_str(
"{name}",
Default::default()
)
.unwrap()
.interpolate_to_string(["Alice"]),
"Alice",
);
// No placeholder (note, the placeholder value is never accessed):
assert_eq!(
Pattern::<SinglePlaceholder>::try_from_str(
"yesterday",
Default::default()
)
.unwrap()
.interpolate_to_string(["hi"]),
"yesterday",
);
// Escaped placeholder and a real placeholder:
assert_eq!(
Pattern::<SinglePlaceholder>::try_from_str(
"'{0}' {1}",
QuoteMode::QuotingSupported.into()
)
.unwrap()
.interpolate_to_string(("hi",)),
"{0} hi",
);
Trait Implementations§
source§impl Clone for SinglePlaceholder
impl Clone for SinglePlaceholder
source§fn clone(&self) -> SinglePlaceholder
fn clone(&self) -> SinglePlaceholder
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 SinglePlaceholder
impl Debug for SinglePlaceholder
source§impl PartialEq for SinglePlaceholder
impl PartialEq for SinglePlaceholder
source§impl PatternBackend for SinglePlaceholder
impl PatternBackend for SinglePlaceholder
source§type PlaceholderKey<'a> = SinglePlaceholderKey
type PlaceholderKey<'a> = SinglePlaceholderKey
The type to be used as the placeholder key in code.
source§type PlaceholderKeyCow<'a> = SinglePlaceholderKey
type PlaceholderKeyCow<'a> = SinglePlaceholderKey
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 SinglePlaceholder
impl Eq for SinglePlaceholder
impl StructuralPartialEq for SinglePlaceholder
Auto Trait Implementations§
impl Freeze for SinglePlaceholder
impl RefUnwindSafe for SinglePlaceholder
impl Send for SinglePlaceholder
impl Sync for SinglePlaceholder
impl Unpin for SinglePlaceholder
impl UnwindSafe for SinglePlaceholder
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