Code Monkey home page Code Monkey logo

rustify's Introduction

Hi there, I'm Josh ๐Ÿ‘‹

  • ๐Ÿ”ญ Iโ€™m currently working on a new blog series
  • ๐ŸŒฑ Iโ€™m currently learning development best practices
  • ๐Ÿ’ฌ Ask me about my homelab
  • ๐Ÿ“ซ How to find me:

Josh's github stats

rustify's People

Contributors

jmgilman avatar justinmir avatar stormshield-gt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rustify's Issues

Requests should have `Content-Type: application/json`

The documentation strongly suggests that the content-type is set to JSON, but this doesn't happen anywhere!

We're using the following middleware โ€ฆ but it would be nice if it was included by default.

pub struct ContentTypeMiddleware;

impl MiddleWare for ContentTypeMiddleware {
    fn request<E>(
        &self,
        _: &E,
        req: &mut http::request::Request<Vec<u8>>,
    ) -> Result<(), ClientError>
    where
        E: Endpoint,
    {
        req.headers_mut()
            .append("content-type", HeaderValue::from_static("application/json"));

        Ok(())
    }

    fn response<E>(
        &self,
        _: &E,
        _: &mut http::response::Response<Vec<u8>>,
    ) -> Result<(), ClientError>
    where
        E: Endpoint,
    {
        Ok(())
    }
}

Would you be open to a PR adding this default behaviour?

Future incompatibility with Rust RFC 3373: Avoid non-local definitions in functions

Rust RFC 3373: Avoid non-local definitions in functions was accepted and it's implementation at rust-lang/rust#120393 found that this crate would be affected by it.

To be more precise users of this crate would be affected by it, in the form of a warn-by-default lint: non_local_definitions. This is because the derive macros from this crate use impl in a local context, const _DERIVE_Endpoint_FOR_???:

let const_name = format!("_DERIVE_Endpoint_FOR_{}", id);
let const_ident = Ident::new(const_name.as_str(), Span::call_site());
quote! {
const #const_ident: () = {

Fortunately I believe a simple fix exist for this crate, by using a const-anon instead of named one (since const-anon are specialized to be "transparent" to their parent):

-    let const_name = format!("_DERIVE_Endpoint_FOR_{}", id);
-    let const_ident = Ident::new(const_name.as_str(), Span::call_site());
     quote! {
-        const #const_ident: () = {
+        const _: () = {

I would suggest applying some form of the patch above as well as releasing a patch version of this crate, as to have a fix available for users before or just after the PR is merged.

cc @jmgilman

Version 0.5.4 is a breaking change. It should be yanked and republished as 0.6

The release 0.5.4 includes changes from #17 where the requirement for http was changed from ^0.2.6 to ^1.0.0.

These are breaking changes because http is a public dependency (its types are leaking into the types defined by rustify) so applying a major semver requirement change on http propagates to rustify.

As an example, this now breaks vaultrs which currently depends on rustify: ^0.5.2 and http: ^0.2.9 and assumes unification between its http version and the one from rustify. See jmgilman/vaultrs#91

I recommend the following actions:

  • rustify 0.5.4 should be yanked immediately
  • rustify 0.6.0 should be released
  • Optional: All public dependencies should be re-exported at the lib root and consumers should avoid relying on implicit cargo version unification

Add support for flatten

Consider case where I want to add new user to endpint '/users'

POST /users/ 

{
    "name": "foobar"
}

I have a common code base that I cannot modify, but it has the definition of User. I would like have the option like serde(flatten):

use common::User;

#[derive(Debug, Clone, Endpoint)]
#[endpoint(
    path = "/users",
    method = "POST",
    response = "()"
)]
struct CreateUser {
    #[endpoint(flatten)]
    user: User
}

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.