Git Product home page Git Product logo

literalext's Introduction

literalext

Build Status

WARNING: This crate is no longer maintained. The literal parsing logic in this crate has been moved into syn 0.12.

To get similar behaviour with syn, parse a syn::Lit by calling syn::parse2::<syn::Lit>(ts) or syn::parse_str::<syn::Lit>(s).

This crate provides extension methods to proc-macro, and proc-macro2's Literal types. These methods provide a mechanism for extracting the value of the type.

API

Adds a trait with implementations for the types proc_macro2::Literal, proc_macro::Literal, and DummyLiteral with the following methods for extracting the value of the type:

pub trait LiteralExt {
    /// If the `Literal` is an integer literal, returns its value.
    fn parse_int(&self) -> Option<IntLit>;

    /// If the `Literal` is a floating point literal, returns its value.
    fn parse_float(&self) -> Option<FloatLit>;

    /// If the `Literal` is a string literal, returns it's value.
    fn parse_string(&self) -> Option<String>;

    /// If the `Literal` is a char literal, returns it's value.
    fn parse_char(&self) -> Option<char>;

    /// If the `Literal` is a byte string literal, returns it's value.
    fn parse_bytes(&self) -> Option<Vec<u8>>;

    /// If the `Literal` is a byte literal, returns it's value.
    fn parse_byte(&self) -> Option<u8>;

    /// If the `Literal` is an inner doc comment (`//!` or `/*!`), returns a
    /// string with the text of the comment.
    fn parse_inner_doc(&self) -> Option<String>;

    /// If the `Literal` is an outer doc comment (`///` or `/**`), returns a
    /// string with the text of the comment.
    fn parse_outer_doc(&self) -> Option<String>;
}

Supported Features

  • i128: Add support for interpreting the i128 and u128 integer types. nightly only

  • proc-macro2 default: Implement LiteralExt on proc_macro2::Literal.

  • proc-macro: Implement LiteralExt on proc_macro::Literal. nightly only

  • dummy: Export a type DummyLiteral with a public constructor which implements the LiteralExt trait.

literalext's People

Contributors

alexcrichton avatar lambda-fairy avatar mystor avatar plietar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

literalext's Issues

include LICENSE text

Apache-2.0 requires text license to be present along with source. MIT has requirement very similar to this.

Please add them. Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.