Git Product home page Git Product logo

struct_fragment's Introduction

StructFragment

A macro to create a duplicate of a struct with keys removed.

I mainly developed this macro to help with creating structs for interacting with the diesel create:

  • original struct is the model, for reads from the database
  • a struct with id removed, used for inserts into the database
  • [coming soon] the ability to do this multiple times, allowing the definition of a struct fragment which would be received as a POST body.

Usage

Either providing a list of ignored fields:

#[derive(StructFragment)]
#[fragment_ignore_list = "id,updated_at"]
#[fragment_name = "DbUser"]
pub struct User {
    pub id: i32,
    pub full_name: String,
    pub email: String,
    pub updated_at: DateTime
}

Or adding #[fragment_ignore] to fields you don't want included.

#[derive(StructFragment)]
#[fragment_name = "DbUser"]
pub struct User {
    #[fragment_ignore] pub id: i32,
    pub full_name: String,
    pub email: String,
    #[fragment_ignore] pub updated_at: DateTime
}

Useful tools

struct_fragment's People

Contributors

keabarnes avatar

Stargazers

Jeff Carpenter avatar Venerdì avatar Ross MacArthur avatar

Watchers

James Cloos avatar  avatar

struct_fragment's Issues

convert "#[fragment*" into function-like interval to support multiple

Currently we have:

#[derive(StructFragment)]
#[fragment_ignore_list = "id,updated_at"]
#[fragment_name = "DbUser"]
pub struct User {
    pub id: i32,
    pub full_name: String,
    pub email: String,
    pub updated_at: DateTime
}

To support multiple duplicates of the same struct, we should change to something like:

#[fragment("DbUser","id,updated_at")]
#[fragment("JsonUser","id,some_other_field")]
pub struct User {
    pub id: i32,
    pub full_name: String,
    pub email: String,
    pub updated_at: DateTime
}

using attribute macros

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.