]>
git.proxmox.com Git - cargo.git/blob - vendor/serde_derive-1.0.11/src/fragment.rs
1 // Copyright 2017 Serde Developers
3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6 // option. This file may not be copied, modified, or distributed
7 // except according to those terms.
9 use quote
::{Tokens, ToTokens}
;
12 /// Tokens that can be used as an expression.
14 /// Tokens that can be used inside a block. The surrounding curly braces are
15 /// not part of these tokens.
19 macro_rules
! quote_expr
{
21 $
crate::fragment
::Fragment
::Expr(quote
!($
($tt
)*))
25 macro_rules
! quote_block
{
27 $
crate::fragment
::Fragment
::Block(quote
!($
($tt
)*))
31 /// Interpolate a fragment in place of an expression. This involves surrounding
32 /// Block fragments in curly braces.
33 pub struct Expr(pub Fragment
);
34 impl ToTokens
for Expr
{
35 fn to_tokens(&self, out
: &mut Tokens
) {
37 Fragment
::Expr(ref expr
) => expr
.to_tokens(out
),
38 Fragment
::Block(ref block
) => {
47 /// Interpolate a fragment as the statements of a block.
48 pub struct Stmts(pub Fragment
);
49 impl ToTokens
for Stmts
{
50 fn to_tokens(&self, out
: &mut Tokens
) {
52 Fragment
::Expr(ref expr
) => expr
.to_tokens(out
),
53 Fragment
::Block(ref block
) => block
.to_tokens(out
),
58 /// Interpolate a fragment as the value part of a `match` expression. This
59 /// involves putting a comma after expressions and curly braces around blocks.
60 pub struct Match(pub Fragment
);
61 impl ToTokens
for Match
{
62 fn to_tokens(&self, out
: &mut Tokens
) {
64 Fragment
::Expr(ref expr
) => {
68 Fragment
::Block(ref block
) => {