pub struct AllocMessage<const N: usize> { /* private fields */ }Expand description
A message format that can be allocated with a fixed number of placeholders.
§Examples
use local_fmt::{AllocMessage, AllocMessageFormat};
let message = AllocMessage::<1>::new(vec![
AllocMessageFormat::AllocText(String::from("Hello, ")),
AllocMessageFormat::Placeholder(0),
]).unwrap();
let formatted = message.format(&["world"]);
assert_eq!(formatted, "Hello, world");Implementations§
Source§impl<const N: usize> AllocMessage<N>
impl<const N: usize> AllocMessage<N>
Sourcepub unsafe fn new_unchecked(format: Vec<AllocMessageFormat>) -> Self
pub unsafe fn new_unchecked(format: Vec<AllocMessageFormat>) -> Self
Creates a new AllocMessage without checking the format.
§Safety
The caller must ensure that the format is correct.
§Examples
use local_fmt::{AllocMessage, AllocMessageFormat};
let message = unsafe {
AllocMessage::<1>::new_unchecked(vec![
AllocMessageFormat::AllocText(String::from("Hello, ")),
AllocMessageFormat::Placeholder(0),
])
};
let formatted = message.format(&["world"]);
assert_eq!(formatted, "Hello, world");Sourcepub fn new(format: Vec<AllocMessageFormat>) -> Result<Self, CreateMessageError>
pub fn new(format: Vec<AllocMessageFormat>) -> Result<Self, CreateMessageError>
Creates a new AllocMessage with format checking.
Returns an error if the format is invalid, such as missing placeholders.
§Examples
use local_fmt::{AllocMessage, AllocMessageFormat, CreateMessageError};
let result = AllocMessage::<1>::new(vec![
AllocMessageFormat::AllocText(String::from("Hello, ")),
AllocMessageFormat::Placeholder(0),
]).unwrap();
let formatted = result.format(&["world"]);
assert_eq!(formatted, "Hello, world");pub fn new_panic(format: Vec<AllocMessageFormat>) -> Self
Sourcepub fn format(&self, args: &[&str; N]) -> String
pub fn format(&self, args: &[&str; N]) -> String
Formats the message with the provided arguments.
§Arguments
args- A slice of string references to be used as arguments in the placeholders.
§Examples
use local_fmt::{AllocMessage, AllocMessageFormat};
let message = AllocMessage::<1>::new(vec![
AllocMessageFormat::AllocText(String::from("Hello, ")),
AllocMessageFormat::Placeholder(0),
]).unwrap();
let formatted = message.format(&["world"]);
assert_eq!(formatted, "Hello, world");pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn formats(&self) -> &Vec<AllocMessageFormat>
Trait Implementations§
Source§impl<const N: usize> Clone for AllocMessage<N>
impl<const N: usize> Clone for AllocMessage<N>
Source§fn clone(&self) -> AllocMessage<N>
fn clone(&self) -> AllocMessage<N>
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<const N: usize> Debug for AllocMessage<N>
impl<const N: usize> Debug for AllocMessage<N>
Source§impl<'de, const N: usize> Deserialize<'de> for AllocMessage<N>
impl<'de, const N: usize> Deserialize<'de> for AllocMessage<N>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<const N: usize> Display for AllocMessage<N>
impl<const N: usize> Display for AllocMessage<N>
Source§impl<const N: usize> FromStr for AllocMessage<N>
impl<const N: usize> FromStr for AllocMessage<N>
Source§impl<const N: usize> Hash for AllocMessage<N>
impl<const N: usize> Hash for AllocMessage<N>
Source§impl<const N: usize> Ord for AllocMessage<N>
impl<const N: usize> Ord for AllocMessage<N>
Source§fn cmp(&self, other: &AllocMessage<N>) -> Ordering
fn cmp(&self, other: &AllocMessage<N>) -> 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<const N: usize> PartialEq for AllocMessage<N>
impl<const N: usize> PartialEq for AllocMessage<N>
Source§impl<const N: usize> PartialOrd for AllocMessage<N>
impl<const N: usize> PartialOrd for AllocMessage<N>
Source§impl<const N: usize> Serialize for AllocMessage<N>
impl<const N: usize> Serialize for AllocMessage<N>
impl<const N: usize> Eq for AllocMessage<N>
impl<const N: usize> StructuralPartialEq for AllocMessage<N>
Auto Trait Implementations§
impl<const N: usize> Freeze for AllocMessage<N>
impl<const N: usize> RefUnwindSafe for AllocMessage<N>
impl<const N: usize> Send for AllocMessage<N>
impl<const N: usize> Sync for AllocMessage<N>
impl<const N: usize> Unpin for AllocMessage<N>
impl<const N: usize> UnwindSafe for AllocMessage<N>
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