SHARE
TWEET

Untitled

a guest Jul 17th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #![allow(unused_variables)]
  2. #![allow(unused_must_use)]
  3.  
  4. use syn::{parse_str, parenthesized, bracketed, braced};
  5. use syn::parse::{Parse, ParseStream, Result};
  6.  
  7. #[derive(Debug)] struct A {}
  8. #[derive(Debug)] struct B {}
  9. #[derive(Debug)] struct C {}
  10.  
  11. impl Parse for A {
  12.     fn parse(input: ParseStream) -> Result<A> {
  13.         let content;
  14.         parenthesized!(content in input);
  15.         Ok(A {})
  16.     }
  17. }
  18.  
  19. impl Parse for B {
  20.     fn parse(input: ParseStream) -> Result<B> {
  21.         let content;
  22.         bracketed!(content in input);
  23.         Ok(B {})
  24.     }
  25. }
  26.  
  27. impl Parse for C {
  28.     fn parse(input: ParseStream) -> Result<C> {
  29.         let content;
  30.         braced!(content in input);
  31.         Ok(C {})
  32.     }
  33. }
  34.  
  35. fn main() {
  36.     dbg!(parse_str::<A>(""));
  37.     dbg!(parse_str::<A>("()"));
  38.     dbg!(parse_str::<A>("( )"));
  39.     dbg!(parse_str::<A>("(1)"));
  40.     dbg!(parse_str::<A>("(a)"));
  41.     dbg!(parse_str::<A>("(\"string\")"));
  42.    
  43.     dbg!(parse_str::<B>(""));
  44.     dbg!(parse_str::<B>("[]"));
  45.     dbg!(parse_str::<B>("[ ]"));
  46.     dbg!(parse_str::<B>("[1]"));
  47.     dbg!(parse_str::<B>("[a]"));
  48.     dbg!(parse_str::<B>("[\"string\"]"));
  49.    
  50.     dbg!(parse_str::<C>(""));
  51.     dbg!(parse_str::<C>("{}"));
  52.     dbg!(parse_str::<C>("{ }"));
  53.     dbg!(parse_str::<C>("{1}"));
  54.     dbg!(parse_str::<C>("{a}"));
  55.     dbg!(parse_str::<C>("{\"string\"}"));
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top