« first day (2083 days earlier)      last day (1420 days later) » 

1:29 AM
How would you slice "up to" a number of elements?
e.g., I have [1, 2] and I want to be able to get a slice of 4 elements
there aren't 4, so I'm happy with 2
but I want it to be limited to 4
using iterators it'd be easy; I'd just take it
if it makes it easier, I want to "zero-pad" it at the end
again, using iterators, I want like iter().chain(repeat(0)).take(4)
but ending up with a slice / array
 
Not bad; don't often see a range as a variable by itself like that
but a good way to keep it consistent
 
you could also, use iterator with a zip
but I believe use copy_from_slice will be more fast
 
I'm surprised that this assembly uses memcpy
 
ofc you could make it uninit to avoid zero init
that a perfect usecase of memcpy
 
1:45 AM
nah, the zero-init is correct/needed — i expect there to be less than 4 elements at times
rust will usually rewrite those memcpy to silly x86 instructions like mov
as a function call is way more expensive than copying 4 bytes
 
this will probably be inline
 
2:03 AM
@Stargateur I just switched to mobile, but try it with a vec instead of array as the src
Arrays can be really optimized
 
didn't see difference
 
 
7 hours later…
9:03 AM
Grrr, this is driving me crazy, I've tried so many things but I was unable to make this work.. how can I run doc tests on private items?
The problem is, when I try to test a struct (and its functionality) I can't just use the name of the struct, I have to import it first (otherwise it is an "undeclared type") but I can't use it, because it is private..
I can't use the #[cfg(doctest)] to make it public either, because the compilation of my crate is happening before my crate is linked against the doc tests..
 
 
5 hours later…
2:19 PM
@PeterVaro pub(crate) ?
 
@Stargateur How on earth would that solve my problem? (I don't want to expose the internals, if anything only conditionally (with a reasonable condition, such as test or doctest!))
 
pub crate allow to use it only in your crate
I don't get what you want to do
 
@Stargateur I can see that ;)
 
 
4 hours later…
6:45 PM
FYI @Stargateur the best solution so far that I found is to define a feature flag, i.e.
$ CARGO_BUILD_RUSTFLAGS='--cfg feature="public-for-doctest"' cargo test
This is far from ideal, because now this feature is passed to every instance of the compiler
But I couldn't find a way, to pass a specific flag to a specific compiler instance (in this case the one that is used when building my crate before the doc-runner links against it)
(Interestingly rustdoc says it will pass down the --cfg flag to rustc, and so I tried CARGO_BUILD_RUSTDOCFLAGS because cargo then will pass down the defined flags to rustdoc but that didn't do the trick..)
It is a shame that doc-tests are considered as integration level tests instead of being unit level ones..
I understand the why they are implemented this way (limitations and practical reasons)
but a massive opportunity missed this way: internal code's documentation cannot be tested easily (though the documentation itself can be generated)
Either way, if any of you have a better idea on how to deal with this, it will be appreciated greatly.
 
7:06 PM
doc tests should be only test public api you are doing it wrong IMO
 
@Stargateur No, I am not. I WANT to document a behaviour of my crate for developers (for me). I'm writing code to illustrate the usage. That is code, which needs to run to verify if it is correct. Private parts could be documented with rustdoc as I described above, so having internal documentation is a know concept. Q.E.D.
 
@Stargateur Why ? Both documentation and unit tests are powerful tools. The fact some function isn't visible out of the crate doesn't mean it's not important or fragile
 
@DenysSéguret ^ +1
 
I have unit tests in broot which exposes no function as it's a program and not a lib. And unit tests in the libraries I built just for broot.
 
So why pub(crate) doesn't work ?
 
7:10 PM
@Stargateur because these are not unit level tests..
They are using your crate, not inside your crate
 
well maybe report this problem in github
 
I'm thinking about raising this for the cargo devs: one should be able to define a different build configuration for the crate used by doc-tests and/or run those separately (including the building and linking) or exclude them from the cargo test suite
 

« first day (2083 days earlier)      last day (1420 days later) »