pub struct FormatString { /* private fields */ }
Expand description
Format string wrapper struct.
This struct wraps a string and has a counter of each template it has with each respective position for the sake of replacing these positions with read data.
Implementations§
Source§impl FormatString
impl FormatString
Sourcepub fn from_data(original: &str, spans: Vec<(String, Range<usize>)>) -> Self
pub fn from_data(original: &str, spans: Vec<(String, Range<usize>)>) -> Self
Compile-time to runtime transformation function.
This function takes data that may be generated
from a macro output and constructs an instance
of FormatString
keeping its fields
private an immutable.
If you use this to construct the instance manually there is no promise that the string and spans are aligned, thus the replacements are going to work.
Parameters
original
- What belongs to theoriginal
field.spans
- What belongs to thespans
field.
Returns An instance of self based on the provided parameters.
Sourcepub fn replace_with(&self, values: HashMap<String, String>) -> String
pub fn replace_with(&self, values: HashMap<String, String>) -> String
Creates replaced original string copy.
This method takes the original string, and replaces it’s templates with the values of the values provided as a hashmap.
Parameters
values
- The values to replace the templates with.
Returns A copy of the original string with it’s templates replaced.
Trait Implementations§
Source§impl FromStr for FormatString
Parse method implementation.
impl FromStr for FormatString
Parse method implementation.
This implementation leads to the implementation
of the parse
method for FormatString
which
parses all the templates on the string and stores
them in a structure along the original string for
future replacement.
Source§impl ToTokens for FormatString
Compile-time to runtime conversion implementation.
impl ToTokens for FormatString
Compile-time to runtime conversion implementation.
This implementation generates a call to the from_data
function in FormatString
.
Source§fn to_tokens(&self, tokens: &mut TokenStream2)
fn to_tokens(&self, tokens: &mut TokenStream2)
Source§fn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
Source§fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
Auto Trait Implementations§
impl Freeze for FormatString
impl RefUnwindSafe for FormatString
impl Send for FormatString
impl Sync for FormatString
impl Unpin for FormatString
impl UnwindSafe for FormatString
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
Source§impl<T> Spanned for Twhere
T: Spanned + ?Sized,
impl<T> Spanned for Twhere
T: Spanned + ?Sized,
Source§fn span(&self) -> Span
fn span(&self) -> Span
Span
covering the complete contents of this syntax tree
node, or Span::call_site()
if this node is empty.