Struct FormatString

Source
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

Source

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 the original field.
  • spans - What belongs to the spans field.

Returns An instance of self based on the provided parameters.

Source

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.

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§

type Err = TemplateError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

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)

Write self to the given TokenStream. Read more
Source§

fn to_token_stream(&self) -> TokenStream

Convert self directly into a TokenStream object. Read more
Source§

fn into_token_stream(self) -> TokenStream
where Self: Sized,

Convert self directly into a TokenStream object. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Spanned for T
where T: Spanned + ?Sized,

Source§

fn span(&self) -> Span

Returns a Span covering the complete contents of this syntax tree node, or Span::call_site() if this node is empty.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.