Giter Club home page Giter Club logo

aturon.github.io's People

Contributors

aturon avatar carols10cents avatar davidszotten avatar japaric avatar jrheard avatar raphlinus avatar rsc avatar skade 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

aturon.github.io's Issues

Line after documentation in rust ?

With a friend of mine, we are coding in rust and we don't know if we should write documentation this way :

/// documentation
fn myfn() {
}

or this way :

/// documentation

fn myfn() {
}

This may seems silly, but you know, choosing style guideline always end up in holy war.

consuming vs. non-consuming builder pattern

@aturon: https://aturon.github.io/ownership/builders.html claims, that non-consuming builder pattern works with the _one-liner-pattern. I think this is wrong - the following code does not compile (copy-paste this to https://play.rust-lang.org/)

#[derive(Debug, Default)]
struct Channel {
    special_info: i32
}

impl Channel {
    fn special_info<VALUE: Into<i32>>(&mut self, value: VALUE) -> &mut Self {
        self.special_info = value.into();
        self
    }
}

fn main() {
    let ch = Channel::default().special_info(42);
    println!("{:?}", ch);
}

results in

error: borrowed value does not live long enough
  --> <anon>:14:14
14 |>     let ch = Channel::default().special_info(42);
   |>              ^^^^^^^^^^^^^^^^^^ does not live long enough
note: reference must be valid for the block suffix following statement 0 at 14:49...
  --> <anon>:14:50
14 |>     let ch = Channel::default().special_info(42);
   |>                                                  ^
note: ...but borrowed value is only valid for the statement at 14:4
  --> <anon>:14:5
14 |>     let ch = Channel::default().special_info(42);
   |>     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider using a `let` binding to increase its lifetime
  --> <anon>:14:5
14 |>     let ch = Channel::default().special_info(42);
   |>     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Therefore I would argue that the consuming-pattern should be the preferred choice to support the one-liner-pattern.

CC @killercup

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.