llogiq / llogiq.github.io Goto Github PK
View Code? Open in Web Editor NEWMy github page
Home Page: https://llogiq.github.io
My github page
Home Page: https://llogiq.github.io
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.
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?
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.
In your recent post, the HTML is rendered incorrectly.
This: 7893166#diff-44f403c1bee078848e6890feebfbef9aR36
Your page about the differences between Java and Rust has at least 2 "it's" vs. "its" errors.
The pub
on this line causes the code not to compile.
The snippet <<Not<True>::Output as Same<False>>::Output
on this line has unbalanced < >
.
Hi,
You have an rss feed at http://llogiq.github.io/feed.xml but thear is no link to it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.