GithubHelp home page GithubHelp logo

metafields.jl's Introduction

MetaFields

Build Status Coverage Status

This package allows defining metadata for fields in a struct, similar to tags in go. But named and inifitely extensible.

They use a similar syntax to Parameters.jl, with a | bar instead of =. You can, in fact, use it as a replacement for Parameters.jl with the aid of Defaults.jl.

@metafield describe ""

@describe mutable struct Described
   a::Int     | "an Int with a description"  
   b::Float64 | "a Float with a description"
end

d = Described(1, 1.0)

julia>describe(d, :a) 
"an Int with a description"  

julia>describe(d, :b) 
"a Float with a description"  

julia>describe(d, :c) 
""  

A more complex example :

using Parameters
@metafield describe ""
@metafield paramrange [0, 1]

@describe @paramrange @with_kw struct Keyword{T}
    a::T = 3 | [0, 100] | "a field with a range, description and default"
    b::T = 5 | [2, 9]   | "another field with a range, description and default"
end

k = Keyword()

julia> describe(k, :b) 
"another field with a range, description and default"

julia> paramrange(k, :a) 
[0, 100]
""  

You can chain as many metafields together as you want.

Just remember that the data for the first @metafield macro goes at the end on the line in the struct. This makes sense when you consider that @with_kw from Parameters.jl has to be the last macro, but the first item in the row after the field type.

You can also update or add fields on a type that is already declared using the same syntax, but you don't need to include all fields, or even their types.

metafields.jl's People

Contributors

rafaqz avatar

Watchers

Waldir Pimenta avatar James Cloos avatar  avatar

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.