#[non_exhaustive]pub enum I18nString {
Literal(CompactString),
Template(CompactString, Box<[I18nString]>),
}Expand description
A string that can be translated into multiple languages.
§Examples
Basic example.
use std::borrow::Cow;
use i18n_string::{I18nString, Resolver};
struct SimpleResolver;
impl Resolver for SimpleResolver {
fn resolve<'s>(&'s self, template: &'s str) -> Cow<'s, str> {
match template {
"world" => Cow::Borrowed("<translated world>"),
_ => template.into(),
}
}
}
let s = I18nString::template("hello {0}, you are {1}", [I18nString::template("world", []), I18nString::literal("123")]);
assert_eq!(s.translate(&SimpleResolver), "hello <translated world>, you are 123");Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Literal(CompactString)
A literal string.
Template(CompactString, Box<[I18nString]>)
A template string.
Implementations§
Source§impl I18nString
impl I18nString
Sourcepub fn literal<S: Into<CompactString>>(s: S) -> Self
pub fn literal<S: Into<CompactString>>(s: S) -> Self
Create a new I18nString::Literal from a string.
§Examples
Basic example.
use i18n_string::I18nString;
let s = I18nString::literal("hello");
assert_eq!(s, I18nString::Literal("hello".into()));Sourcepub fn template<S: Into<CompactString>, ARGS: IntoIterator<Item = I18nString>>(
s: S,
args: ARGS,
) -> Self
pub fn template<S: Into<CompactString>, ARGS: IntoIterator<Item = I18nString>>( s: S, args: ARGS, ) -> Self
Create a new I18nString::Template from a string and arguments.
§Examples
Basic example.
use i18n_string::I18nString;
let s = I18nString::template("hello {}", [I18nString::literal("world")]);
assert_eq!(s, I18nString::Template("hello {}".into(), [I18nString::Literal("world".into())].into()));Trait Implementations§
Source§impl Clone for I18nString
impl Clone for I18nString
Source§fn clone(&self) -> I18nString
fn clone(&self) -> I18nString
Returns a duplicate 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 I18nString
impl Debug for I18nString
Source§impl Display for I18nString
impl Display for I18nString
Source§impl FromStr for I18nString
impl FromStr for I18nString
Source§impl Hash for I18nString
impl Hash for I18nString
Source§impl I18nStringBuilderExt for I18nString
impl I18nStringBuilderExt for I18nString
Source§fn display<D: Display + ?Sized>(display: &D) -> Self
fn display<D: Display + ?Sized>(display: &D) -> Self
Create a new
I18nString::Literal from a Display type.Source§fn debug<D: Debug + ?Sized>(debug: &D) -> Self
fn debug<D: Debug + ?Sized>(debug: &D) -> Self
Create a new
I18nString::Literal from a Debug type.Source§impl I18nStringTranslateExt for I18nString
impl I18nStringTranslateExt for I18nString
Source§fn to_no_translate_string(&self) -> String
fn to_no_translate_string(&self) -> String
Translate the
I18nString into a no-translate string. Read moreSource§impl Ord for I18nString
impl Ord for I18nString
Source§fn cmp(&self, other: &I18nString) -> Ordering
fn cmp(&self, other: &I18nString) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for I18nString
impl PartialEq for I18nString
Source§impl PartialOrd for I18nString
impl PartialOrd for I18nString
impl Eq for I18nString
impl StructuralPartialEq for I18nString
Auto Trait Implementations§
impl Freeze for I18nString
impl RefUnwindSafe for I18nString
impl Send for I18nString
impl Sync for I18nString
impl Unpin for I18nString
impl UnwindSafe for I18nString
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§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
Fallible version of
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
Converts the given value to a
CompactString. Read more