[−][src]Trait genco::tokens::FormatInto
Trait for types that can be formatted in-place into a token stream.
Things implementing FormatInto can be used as arguments for interpolation in the quote! macro.
from_fn() is a helper function which simplifies the task of creating a FormatInto implementation on the fly.
Examples
use genco::quote_in; use genco::tokens::{ItemStr, FormatInto, from_fn, static_literal}; use genco::lang::Lang; fn comment<L>(s: impl Into<ItemStr>) -> impl FormatInto<L> where L: Lang { from_fn(move |tokens| { let s = s.into(); quote_in!(*tokens => #(static_literal("//")) #s); }) }
Required methods
fn format_into(self, tokens: &mut Tokens<L>)
Convert the type into tokens in-place.
A simple way to build ad-hoc format_into implementations is by using the from_fn() function.
Implementations on Foreign Types
impl<L, T> FormatInto<L> for Vec<T> where
L: Lang,
T: FormatInto<L>,
[src]
L: Lang,
T: FormatInto<L>,
Formatting a vector of token streams is like formatting each, one after another.
Examples
use genco::prelude::*; let mut vec = Vec::<Tokens>::new(); vec.push(quote!(foo)); vec.push(quote!(#<space>bar)); let result = quote!(#vec baz); assert_eq!("foo bar baz", result.to_string()?);
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<'a, L, T> FormatInto<L> for &'a [T] where
L: Lang,
T: Clone + FormatInto<L>,
[src]
L: Lang,
T: Clone + FormatInto<L>,
Formatting a slice of token streams is like formatting each, one after another.
This will cause each token stream to be cloned into the destination stream.
Examples
use genco::prelude::*; let vec = vec!["foo", " ", "bar"]; let slice = &vec[..]; let result: Tokens = quote!(#slice baz); assert_eq!("foo bar baz", result.to_string()?);
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<'a, L> FormatInto<L> for &'a str where
L: Lang,
[src]
L: Lang,
Formatting borrowed string boxed them on the heap.
Examples
use genco::prelude::*; let foo = "foo"; let bar = "bar"; let result: Tokens = quote!(#foo #bar baz); assert_eq!("foo bar baz", result.to_string()?);
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<'a, L> FormatInto<L> for &'a String where
L: Lang,
[src]
L: Lang,
Formatting borrowed string boxed them on the heap.
Examples
use genco::prelude::*; let foo = String::from("foo"); let bar = String::from("bar"); let result: Tokens = quote!(#(&foo) #(&bar) baz); assert_eq!("foo bar baz", result.to_string()?);
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<L> FormatInto<L> for String where
L: Lang,
[src]
L: Lang,
Formatting owned strings takes ownership of the string directly from the heap.
Examples
use genco::prelude::*; let foo = String::from("foo"); let bar = String::from("bar"); let result: Tokens = quote!(#foo #bar baz); assert_eq!("foo bar baz", result.to_string()?);
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<L> FormatInto<L> for Rc<String> where
L: Lang,
[src]
L: Lang,
Refcounted strings are moved into the token stream without copying.
Examples
use genco::prelude::*; use std::rc::Rc; let foo = Rc::new(String::from("foo")); let bar = Rc::new(String::from("bar")); let result: Tokens = quote!(#foo #bar baz); assert_eq!("foo bar baz", result.to_string()?);
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<'a, L> FormatInto<L> for &'a Rc<String> where
L: Lang,
[src]
L: Lang,
Refcounted strings are cloned and moved into the token stream without copying.
Examples
use genco::prelude::*; use std::rc::Rc; let foo = Rc::new(String::from("foo")); let bar = Rc::new(String::from("bar")); let result: Tokens = quote!(#(&foo) #(&bar) baz); assert_eq!("foo bar baz", result.to_string()?);
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<L, T> FormatInto<L> for Option<T> where
L: Lang,
T: FormatInto<L>,
[src]
L: Lang,
T: FormatInto<L>,
Optional items are formatted if they are present.
Examples
use genco::prelude::*; use std::rc::Rc; let foo = Some("foo"); let bar = Some("bar"); let biz = None::<&str>; let result: Tokens = quote!(#foo #bar baz #biz); assert_eq!("foo bar baz", result.to_string()?);
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<L> FormatInto<L> for u8 where
L: Lang,
[src]
L: Lang,
Implementation for primitive type. Uses the corresponding Display implementation for the primitive type.
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<L> FormatInto<L> for u16 where
L: Lang,
[src]
L: Lang,
Implementation for primitive type. Uses the corresponding Display implementation for the primitive type.
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<L> FormatInto<L> for u32 where
L: Lang,
[src]
L: Lang,
Implementation for primitive type. Uses the corresponding Display implementation for the primitive type.
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<L> FormatInto<L> for u64 where
L: Lang,
[src]
L: Lang,
Implementation for primitive type. Uses the corresponding Display implementation for the primitive type.
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<L> FormatInto<L> for u128 where
L: Lang,
[src]
L: Lang,
Implementation for primitive type. Uses the corresponding Display implementation for the primitive type.
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<L> FormatInto<L> for i8 where
L: Lang,
[src]
L: Lang,
Implementation for primitive type. Uses the corresponding Display implementation for the primitive type.
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<L> FormatInto<L> for i16 where
L: Lang,
[src]
L: Lang,
Implementation for primitive type. Uses the corresponding Display implementation for the primitive type.
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<L> FormatInto<L> for i32 where
L: Lang,
[src]
L: Lang,
Implementation for primitive type. Uses the corresponding Display implementation for the primitive type.
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<L> FormatInto<L> for i64 where
L: Lang,
[src]
L: Lang,
Implementation for primitive type. Uses the corresponding Display implementation for the primitive type.
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<L> FormatInto<L> for i128 where
L: Lang,
[src]
L: Lang,
Implementation for primitive type. Uses the corresponding Display implementation for the primitive type.
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<L> FormatInto<L> for isize where
L: Lang,
[src]
L: Lang,
Implementation for primitive type. Uses the corresponding Display implementation for the primitive type.
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<L> FormatInto<L> for usize where
L: Lang,
[src]
L: Lang,
Implementation for primitive type. Uses the corresponding Display implementation for the primitive type.
fn format_into(self, tokens: &mut Tokens<L>)
[src]
Implementors
impl FormatInto<Csharp> for genco::lang::csharp::Import
[src]
fn format_into(self, tokens: &mut Tokens<Csharp>)
[src]
impl FormatInto<Dart> for genco::lang::dart::Import
[src]
fn format_into(self, tokens: &mut Tokens<Dart>)
[src]
impl FormatInto<Go> for genco::lang::go::Import
[src]
fn format_into(self, tokens: &mut Tokens<Go>)
[src]
impl FormatInto<Java> for genco::lang::java::Import
[src]
fn format_into(self, tokens: &mut Tokens<Java>)
[src]
impl FormatInto<JavaScript> for genco::lang::js::Import
[src]
fn format_into(self, tokens: &mut Tokens<JavaScript>)
[src]
impl FormatInto<Python> for genco::lang::python::Import
[src]
fn format_into(self, tokens: &mut Tokens<Python>)
[src]
impl FormatInto<Python> for ImportModule
[src]
fn format_into(self, tokens: &mut Tokens<Python>)
[src]
impl FormatInto<Rust> for genco::lang::rust::Import
[src]
fn format_into(self, tokens: &mut Tokens<Rust>)
[src]
impl FormatInto<Swift> for genco::lang::swift::Import
[src]
fn format_into(self, tokens: &mut Tokens<Swift>)
[src]
impl<'a> FormatInto<Csharp> for &'a genco::lang::csharp::Import
[src]
fn format_into(self, tokens: &mut Tokens<Csharp>)
[src]
impl<'a> FormatInto<Dart> for &'a genco::lang::dart::Import
[src]
fn format_into(self, tokens: &mut Tokens<Dart>)
[src]
impl<'a> FormatInto<Go> for &'a genco::lang::go::Import
[src]
fn format_into(self, tokens: &mut Tokens<Go>)
[src]
impl<'a> FormatInto<Java> for &'a genco::lang::java::Import
[src]
fn format_into(self, tokens: &mut Tokens<Java>)
[src]
impl<'a> FormatInto<JavaScript> for &'a genco::lang::js::Import
[src]
fn format_into(self, tokens: &mut Tokens<JavaScript>)
[src]
impl<'a> FormatInto<Python> for &'a genco::lang::python::Import
[src]
fn format_into(self, tokens: &mut Tokens<Python>)
[src]
impl<'a> FormatInto<Python> for &'a ImportModule
[src]
fn format_into(self, tokens: &mut Tokens<Python>)
[src]
impl<'a> FormatInto<Rust> for &'a genco::lang::rust::Import
[src]
fn format_into(self, tokens: &mut Tokens<Rust>)
[src]
impl<'a> FormatInto<Swift> for &'a genco::lang::swift::Import
[src]
fn format_into(self, tokens: &mut Tokens<Swift>)
[src]
impl<'a, L> FormatInto<L> for &'a ItemStr where
L: Lang,
[src]
L: Lang,
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<'a, L> FormatInto<L> for &'a Tokens<L> where
L: Lang,
[src]
L: Lang,
Formatting a reference to a token stream is exactly the same as extending the token stream with a copy of the stream being formatted.
Examples
use genco::prelude::*; let a: &Tokens = "e!(foo bar); let result = quote!(#a baz); assert_eq!("foo bar baz", result.to_string()?);
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<L> FormatInto<L> for Item<L> where
L: Lang,
[src]
L: Lang,
Formatting an item is the same as adding said item to the token stream through item().
Examples
use genco::prelude::*; use genco::tokens::{Item, ItemStr}; let foo = Item::Literal(ItemStr::Static("foo")); let bar = Item::Literal(ItemStr::Box("bar".into())); let result: Tokens = quote!(#foo #bar baz); assert_eq!("foo bar baz", result.to_string()?); assert_eq!{ vec![ Item::Literal(ItemStr::Static("foo")), Item::Space, Item::Literal(ItemStr::Box("bar".into())), Item::Space, Item::Literal(ItemStr::Static("baz")), ] as Vec<Item<()>>, result, };
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<L> FormatInto<L> for ItemStr where
L: Lang,
[src]
L: Lang,
Convert stringy things.
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<L> FormatInto<L> for Tokens<L> where
L: Lang,
[src]
L: Lang,
fn format_into(self, tokens: &mut Self)
[src]
impl<L, F> FormatInto<L> for FromFn<F> where
L: Lang,
F: FnOnce(&mut Tokens<L>),
[src]
L: Lang,
F: FnOnce(&mut Tokens<L>),
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<T> FormatInto<Csharp> for genco::lang::csharp::BlockComment<T> where
T: IntoIterator,
T::Item: Into<ItemStr>,
[src]
T: IntoIterator,
T::Item: Into<ItemStr>,
fn format_into(self, tokens: &mut Tokens<Csharp>)
[src]
impl<T> FormatInto<Csharp> for Comment<T> where
T: IntoIterator,
T::Item: Into<ItemStr>,
[src]
T: IntoIterator,
T::Item: Into<ItemStr>,
fn format_into(self, tokens: &mut Tokens<Csharp>)
[src]
impl<T> FormatInto<Dart> for DocComment<T> where
T: IntoIterator,
T::Item: Into<ItemStr>,
[src]
T: IntoIterator,
T::Item: Into<ItemStr>,
fn format_into(self, tokens: &mut Tokens<Dart>)
[src]
impl<T> FormatInto<Java> for genco::lang::java::BlockComment<T> where
T: IntoIterator,
T::Item: Into<ItemStr>,
[src]
T: IntoIterator,
T::Item: Into<ItemStr>,
fn format_into(self, tokens: &mut Tokens<Java>)
[src]
impl<T, L> FormatInto<L> for Display<T> where
L: Lang,
T: Display,
[src]
L: Lang,
T: Display,
fn format_into(self, tokens: &mut Tokens<L>)
[src]
impl<T, L> FormatInto<L> for QuotedFn<T> where
L: Lang,
T: FormatInto<L>,
[src]
L: Lang,
T: FormatInto<L>,
fn format_into(self, t: &mut Tokens<L>)
[src]
impl<T, L> FormatInto<L> for RegisterFn<T> where
T: Register<L>,
L: Lang,
[src]
T: Register<L>,
L: Lang,