Giter VIP home page Giter VIP logo

llogiq.github.io's People

Contributors

4tm4j33tk4ur avatar aochagavia avatar benaryorg avatar carols10cents avatar erismart avatar gkoz avatar hallmark avatar killercup avatar kud1ing avatar leseulartichaut avatar llogiq avatar manishearth avatar matematikaadit avatar notriddle avatar remram44 avatar simonwoodburyforget avatar vwim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

llogiq.github.io's Issues

Helper function: inner_expr

This function could unwrap parentheses and single-expression blocks, as well as follow constant paths. This is quite useful in a lot of places, actually.

Ambiguous sentence in 'From / Into article'

In the 'From / Into article', when I read the sentence "In our case, we also have a Blob type which contains a Bar and a Buzz type which can be converted to a Bar.", I interpreted this incorrectly as:

struct Blob {
    bar: Bar,
    buzz: Buzz,
}

The correct code is just below, but I was reading on my phone, where it's not immediately visible. Perhaps the sentence could be reworded, or the code positioned first, followed by the explanation?

Comments through Hash

Here are some disorganized comments (through Hash). I'm not an expert so some of my comments may not be completely correct.

OIBIT

Maybe you shouldn't expand this... OIBIT traits are actually opt-out and don't even have to be built-in (IIRC).

Since Eq is basically empty (apart from a pre-defined marker method), auto-deriving has no chance of doing something interesting, so it won't.

What marker method?

The Index and IndexMut traits specify the indexing operation, e.g. x[y] and x[y] = z, respectively (well the latter is a lie, IndexMut does not actually assign the value, but returns an lvalue ready for assigning).

More importantly, IndexMut returns a mutable reference (sort of). You can not only assign but can mutate in-place.

the Fn*-traits abstract the act of calling something. The difference between those traits is simply how the self is taken: Fn takes it by reference, FnMut by mutable reference and FnOnce consumes it directly (which is after all why it can only be called once, as there is no self to call afterwards).

For consistency, I'd say that FnOnce consumes it by-value. Also, it might be worth mentioning that these traits can't be implemented manually in stable rust.

Display and Debug are used for formatting values for display, respectively.

Opinionated nits.

Should you decide to implement Debug manually, you may want to distinguish between the normal {:?} format specifier and the pretty-printing {:#?} one. You can do this by querying the Formatter::flags() method, which will have the 4 bit set (which I found out by experiment). Thus, if (f.flags() & 4) == 4 is true, the caller asked you to produce pretty-printed output. Note that this is expressly not a public part of Debug/Formatter's interface, so the Rust gods could change this the moment I write this.

The best way to do this is to just use debug builders. This way, you don't have to care if pretty-printing is requested.

Copy and Clone

Those two traits take care of getting another object from one you already have.

duplicating?

There are exactly two reasons not to implement Copy: Either your type cannot be Copyable, because it contains references, or your type is so big that copying it would be prohibitively expensive (e.g. it could contain an [f64; 65536]).

Should probably explain (or link) auto-copy semantics (versus move).

Clone is a more generic solution that will take care of any references. You will probably want to auto-derive it in most cases (as being able to clone values is rather useful), and only implement it manually for things like custom refcounting schemes, garbage collection or something similar.

Cloning is also explicit (to contrast it with the auto-copy semantics of copy).

Default

Might want to mention MyStruct { field: value, ..Default::default() } syntax.

Aside: This is also the reason why HashMap does not implement Hash itself, because two equal hash maps could still store their contents in different order, resulting in different hashes, which would break the hashing contract.

HashMap could implement hash if the values implemented hash (and eq). You just have to make sure the order doesn't change the hash value. For example, you could create a vector of (hash(key), hash(value)) tuples, sort that, and then hash it. Of course, this would be kind of slow.

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.