-
Moongoodboy{K}
silentk: Why might they exit?
-
silentk
Moongoodboy{K}: they are running GUI windows that may receive close events, so those threads would need to be joined before the other window / thread should be able to restart them
-
silentk
-
silentk
How is num shared between the threads?
-
silentk
Ownership goes to the thread from the mutex everytime it calls lock()?
-
Moongoodboy{K}
silentk: `num` (declared on line 10 in that snippet) is a smart pointer representing a borrow of an i32 which is owned by the `Mutex`.
-
Moongoodboy{K}
The Mutex owns the i32; lock() loans it to you.
-
Moongoodboy{K}
…lends.
-
iceiceice
hi i have a question about structs and lifetimes
-
Moongoodboy{K}
~ask @ iceiceice
-
rustybot
iceiceice: Got a question about Rust? Go ahead and ask it! If you need to paste code, please use
play.rust-lang.org and click "Share" for a link
-
iceiceice
I have a struct A that holds some data, and has no lifetime parameter, and B that depends on A and binds to its lifetime parameter.
-
iceiceice
I would like to combine these into one struct that abstracts this all and has no lifetime parameter
-
iceiceice
and make B use the lifeitme of the A member as its parameter
-
iceiceice
is that kind of thing possible or not?
-
iceiceice
i didn't see it in the docu
-
Moongoodboy{K}
The type that wraps both of these would be a self-referential type, which are tricky.
-
Moongoodboy{K}
You may be interested in {~crate rental}.
-
rustybot
rental (0.5.2) - A macro to generate safe self-referential structs, plus premade types for common use cases. ->
crates.io/crates/rental <
docs.rs/rental>
-
Cocalus
Also {~crate owning_ref}
-
rustybot
owning_ref (0.4.0) - A library for creating references that carry their owner with them. ->
crates.io/crates/owning_ref <
kimundi.github.io/owning-ref-rs/owning_ref/index.html>
-
iceiceice
why is it a self referential type?
-
Cocalus
The Struct C that holds A and B, contains a reference (in B) that Points to another part of C (in A)
-
gchristensen
are there rust fn's for setting mtime and atime?
-
Cocalus
What decides when there can be two versions of a crate. I have two third party dependencies on byteorder, one which oddly uses version "~1.2.1", the other "1.3.1". Which can't update due to the conflict but I've seem multiple versions of dependencies build before.
-
sfackler
~ constraints interact poorly with cargo's dependency resolution
-
sfackler
~1.2.1 means >= 1.2.0, < 1.3.0 iirc
-
sfackler
but cargo won't build two 1.x versions because they should be compatible
-
wpage
I think klabnik is actually working on those types of problems now
-
wpage
there was a reddit post about him formalizing some of the version constraint specifications, etc
-
Cocalus
Why can't that dependency use 1.2.1 and the other 1.3.1. I know there can't be multiple versions of c sys crates, but I don't think should affect byteorder
-
ldiamond
I have a public function that returns a function which takes stuff out of a channel and pushes that to an http server using reqwest. In javascript for example, I'd put all dependencies as parameters with default values (then in a test I can override the dependency using a moc). What's the right way to do that in rust considering there's no default parameter values?
-
silentk
Is there a trello board etc somewhere for tracking and understanding the dependency issues in flight?
-
silentk
There are default values, and you can control initialization via adding some default traits.
-
silentk
I've implemented a ::default method, but I don't think it's quite the same.
-
ldiamond
silentk: So you're saying I should define a struct with the params that implements the default trait and pass that struct instead of parameters?
-
ldiamond
It's a bit verbose isn't it?
-
krobelus
-
krobelus
ldiamond: that seems like the way to go, create a tuple struct, e.g. FunParams(type1, type2, ...)
-
gchristensen
krobelus: doesn't seem like that allows setting?
-
gchristensen
oh! utimeensat
-
gchristensen
thanks!
-
krobelus
gchristensen: i don't see it right now, how do you set the mtime? not with syscall i assume
-
gchristensen
touch can do it
-
Moongoodboy{K}
krobelus: changing file timestamps is a syscall, yeah
-
neachdainn
Hey all. Why is Rustup telling me that there is no rustfmt component for x86_64 Darwin?
-
neachdainn
"error: toolchain 'stable-x86_64-apple-darwin' does not contain component 'rustfmt' for target 'x86_64-apple-darwin'"
-
stephaneyfx
neachdainn: What is the output of `rustc --version` and `rustup --version`?
-
neachdainn
rustc 1.32.0 (9fda7c223 2019-01-16) and rustup 1.16.0 (beab5ac2b 2018-12-06)
-
neachdainn
I thought I was on the latest Rustc, so update that and then try again
-
neachdainn
That did not fix it
-
stephaneyfx
neachdainn: May you share the output of `rustup component list` on
paste.rs?
-
neachdainn
Here you go!
paste.rs/pxD
-
neachdainn
I did install the preview on stable, but I'm really trying to install the nightly version and I'm getting the same error for both
-
neachdainn
I did install it on stable *a while ago*
-
stephaneyfx
The component is still named rustfmt-preview. Weird, I thought it was renamed to rustfmt stable (and it is on my Windows system)
-
neachdainn
Then I suppose there is a "bug" somewhere, because distinctly tells me to install "rustfmt"
-
neachdainn
"error: 'cargo-fmt' is not installed for the toolchain 'nightly-x86_64-apple-darwin' \n To install, run `rustup component add rustfmt`"
-
stephaneyfx
I remember reading an issue that might be related. Let me try to find it...
-
neachdainn
Rustfmt-preview isn't available on nightly.
-
stephaneyfx
Were you talking about stable initially?
-
stephaneyfx
Weren't*
-
neachdainn
My original goal was nightly, but the same issue was happening on stable and I was under the impression that clippy and rustfmt sometimes drop out of nightly
-
stephaneyfx
Your impression is right
-
ldiamond
krobelus: that doesn't allow me to only override some dependencies and not others
-
neachdainn
How would I have Rustfmt skip a doctest but not the rest of the documentation?
-
neachdainn
Can I do something like `/// # #![rustfmt::skip]`?
-
stephaneyfx
neachdainn: Have you tried this? `rustup uninstall stable`, `rustup self update`, `rustup install stable`
-
stephaneyfx
(for your earlier issue)
-
neachdainn
Will try it!
-
stephaneyfx
And then check the list of components with `rustup component list` to see if it includes rustfmt or rustfmt-preview.
-
neachdainn
stephaneyfx: That worked with "rustfmt". Thanks!
-
stephaneyfx
neachdainn: You're welcome :)
-
ebulkin
hey all, is there a more advanced criterion reference?
-
ebulkin
I'm trying to find a canonical way to do a benchmark "with set-up" so to speak
-
ebulkin
i.e. populate a struct with 1000 things, then see how performant adding 1 item is
-
silentk
Do most mutexes live in ARC's?
-
neachdainn
Arc and static variables are probably the most common
-
Ralith
sometimes I put one inside something that is transitively contained by an `Arc`, instead of directly within the `Arc`
-
neachdainn
So my CI Rustfmt isn't respecting `format_doc_comments = false` and is attempting to format the code in an insane way. Is there any way to force it to not try and format doctests?
-
neachdainn
-
Dabo
has anyone worked with transforming generic code in proc macros via syn? I'm roughly trying to turn #[my_macro] impl X { fn get<T:Clone>(x: T) -> Res { ... } } into impl<T:Clone> MyTrait<T> for X { type Result = Res; fn get(x: T) -> Res { ... } }
-
Dabo
the syntax transformation works, and if I run `cargo expand` on my test I get the output I think it should have
-
Dabo
but when compiling, it errors with "cannot find type `T` in this scope" pointing to the `T` in `x: T`
-
Dabo
My transformation process for the generics is to clone the `syn::Generics` from the method signature, use `split_for_impl`, and stick the `impl_generics` and `where_generics` into the result using `quote!{ }`
-
Dabo
I haven't come up with a minimal example yet since I have so much plumming in the macro crate, but here's some input/output/errors in a gist:
-
Dabo
-
silentk
Can a struct pass itself into a thread somehow during spawn?
-
Dabo
if a struct method takes 'self' by value it can do anything with itself, including use `self` in a closure passed to thread::spawn
-
snek
what is the rust equiv of `class Value; class Name : Value; class String : Name; class Symbol : Name; unordered_map<Name, Value>`
-
silentk
-
silentk
compiler wants me to assign Mutex<Option<JoinHandle<Thread>>> rather than <Option<JoinHandle...
-
silentk
My understanding is that we put mutex protected things inside of the mutex itself? Does this include overwriting what that Mutex holds?
-
GreenJello
silentk, try: *acquired = Some(handle)
-
snek
GreenJello: funny seeing you here
-
jxcl
Hi guys! I'm using VecDeque to collect u8s. I'd like to convert the final product to a String. I see that VecDeque supports IntoIter so I can get an Iter<u8> but I don't see a method that returns Option<String> from an Iter<u8>. Is there a way I can convert between these two types? I know that I can convert to a Vec<u8> and get a string from there but I was hoping to avoid the extra conversion.
-
Mutabah
jxcl: Collecting into a Vec then converting that into a String shouldn't be too expensive
-
Mutabah
(The Vec->String conversion should just be a validation pass, no reallocation)
-
Mutabah
I think there's also a VecDeque method that shuffles data around so you can get a single contigious slice?
-
jxcl
ah yes, of course, dequeue doesn't necessary have a contiguous slice by default so it requires conversion into a contiguous data type
-
jxcl
that makes sense, thanks Mutabah!
-
mib_c27p6u
hello
-
mib_c27p6u
is it possible for trait to have attribute, so the implementator must have that attribute, and trait can use modify that attribute
-
Mutabah
mib_c27p6u: You mean a field, like `trait Foo { bar: u32; }`?
-
mib_c27p6u
ywow
-
mib_c27p6u
yes
-
mib_c27p6u
that's what I mean
-
mib_c27p6u
but I'm trying to add it make error, missing `fn`, `type`, or `const`
-
Dabo
it isn't possible - traits can only have functions, constants and associated types at the moment
-
mib_c27p6u
I see
-
mib_c27p6u
damn
-
mib_c27p6u
or can I make some generic that have particular field ?
-
Mutabah
mib_c27p6u: What do you mean by that?
-
Dabo
mib_c27p6u, in general, no - the standard solution is to just provide functions which give access to what you want
-
Dabo
if a trait has functions `bar() -> &u32` and `bar_mut() -> &mut u32` then you have all the functionality of being able to access a field
-
Dabo
* `fn bar(&self) -> &u32` and `fn bar(&mut self) -> &mut u32`
-
mib_c27p6u
oke, that get set solve it for now
-
mib_c27p6u
thank you everyone
-
jxcl
I have a &[u8] that I'm trying to filter and create a new Vec<u8> from. However when I try to call &[u8].into_iter().filter().collect() I'm getting a vector of references instead. Do I have to explicitly clone the u8s into a vector or is there a simpler solution I'm missing?
-
Arnavion
.cloned()
-
Dabo
^^ you'll need to clone the `u8`s since the `&[u8]` is just a reference to them. Since u8 is Copy data though it won't be costly
-
Arnavion
Iterator<&T>::cloned() produces an Iterator<T> if T: Clone, which &u8 is
-
Dabo
if you don't need to iterate and map though, the `to_vec()` method is probably simpler
-
Dabo
nevermind, missed the filter
-
jxcl
.cloned() is what I was looking for. Thanks!
-
jxcl
I was hoping I wasn't going to have to .map(|&x| x.clone()) lol
-
Moongoodboy{K}
since it's Copy, `.map(|&b| b)`
-
Moongoodboy{K}
but yeah, `.cloned()` :)
-
Arnavion
eval: --nightly #![feature(iter_copied)] let _: Vec<u8> = vec![&5_u8].into_iter().copied().collect(); // and one day, this
-
eval
()
-
jxcl
does that take advantage of the Copy trait for some performance gain?
-
Arnavion
If the underlying type was Copy there is no difference between cloned() and copied()
-
Mutabah
well, unless someone has manually implemented Clone in some strange way
-
Arnavion
The (auto-derived) Clone impl of a Copy type just forwards to the Copy impl, ie fn clone(&self) -> Self { *self }
-
jxcl
so why add the extra method?
-
Arnavion
Right, but if they impled Clone manually for a Copy type then they're asking for trouble. There's even a clippy lint for it
-
Arnavion
jxcl: To ensure that it only works for Copy types, not Clone types
-
jxcl
ah, duh
-
jxcl
(Advent of Code day 5 spoilers)
github.com/jxcl/aoc_2018/blob/master/day05/src/main.rs this is what y'all have been helping me with btw. I'm pretty happy with this solution
-
Kingsquee
-
Mutabah
bug report!
-
Trangar
ICE ICE baby
-
Trangar
How does that even happen?
-
scottmcm
I guessing there's an error and the diagnostic output is trying to slice the string in the wrong place
-
jebrosen
pub use $mod_name; is illegal there, and it actually fails in rustc_resolve::Resolver::report_conflict
-
Kingsquee
-
Trangar
Neat
-
user64
Is there a slice method like find_mut but with another name that I can't find? or is using position() and get_mut() really the right way?
-
Trangar
What do you want to do exactly?
-
Trangar
I think .iter_mut().find() would be the same as .iter().position() and .get_mut()
-
user64
Trangar: yeah that worked, dah.
-
rom
"trait MyTrait : OtherTrait + 'static {}" → what is the meaning of a 'static lifetime here?
-
rom
ah ok we cannot implement it for structs with a non-static lifetime
-
rom
impl<'a> MyTrait for MyStruct<'a> {} does not compile
-
Trangar
-
rom
Trangar, thx
-
ejpbruel
hi folks
-
ejpbruel
i have a quick question
-
ejpbruel
i have a line of code that looks like this:
-
ejpbruel
self.half_edge_mut(self.half_edge(b_onext).unwrap().sym).unwrap().lnext = a
-
ejpbruel
half_edge_mut is a getter like function that returns an Option<&mut HalfEdge>, half_edge returns a Option<&HalfEdge>
-
ejpbruel
this code works fine as it is
-
ejpbruel
now i tried to do:
-
ejpbruel
self[self[b_onext].sym].lnext = a;
-
ejpbruel
this is essentially the same code, except i've used the Index trait to forward to half_edge/half_edge_mut
-
ejpbruel
but now the borrow checker complains that i cannot borrow self mutably in the outer use, because its already borrowed immutably in the inner use
-
ejpbruel
fair enough, but then why did it work in the first case?
-
Trangar
.unwrap() doesn't return a reference, but self[b_onext] does
-
Trangar
So .unwrap() returns T, which doesn't borrow self, but self[b_onext] returns &T
-
Mutabah
Trangar: The unwrap is of a &T
-
ejpbruel
right
-
Trangar
The easiest thing you can do is say `let index: T = self[b_onext].sym; self[index].lnext = a;"
-
ejpbruel
so theres still a reference
-
Mutabah
I think the second case doesn't work because the borrowck feature that makes the first one work doesn't apply to indexing... for some reason
-
ejpbruel
Tranger: yeah, that will fix my problem. im mainly trying to understand why the first *is* allowed.
-
Trangar
I think rustc generally gets a bit confused with onelines and borrow checking
-
Kinnison
Could this be a limit of how NLLs work?
-
ejpbruel
Mutabah: thats... weird
-
Mutabah
(strange, I'd expect that NLL borrowcheck would be working on the MIR, which is after custom operators are expanded)
-
ejpbruel
Kinnison: this is on stable, so im assuming NLL doesnt factor in here?
-
Kinnison
ejpbruel: i thought NLL was stable now
-
ejpbruel
is it?
-
ejpbruel
then im even more confused :D
-
Kinnison
-
ejpbruel
so possibly NLL is what makes the first case work, but somehow not the second?
-
Kinnison
1.31
-
Trangar
I wonder if it's because index arguments are a lower execution priority than function arguments
-
Kinnison
It's possible. Niko did ask for minimal use-cases where it fails to work in unexpected ways, so I imagine a well composed github issue would be well received
-
ejpbruel
Kinnison: whats the proper place to open these issues?
-
Kinnison
ejpbruel: I'd guess github.com/rust-lang/rust
-
ejpbruel
Kinnison: ill file an issue!
-
Kingsquee
-
Mutabah
Kingsquee: It overflows the stack if not boxed too
-
Kingsquee
Mutabah, I'm aware
-
Kingsquee
but if it's not allocated on the stack why would it overflow the stack
-
Kingsquee
box == heap alloc, to my understanding
-
Mutabah
The starting value is located on the stack, then moved into the heap
-
Kingsquee
wait what
-
Kingsquee
it's moved
-
Kingsquee
ai yai yai
-
Mutabah
Yes.
-
paradoxspiral
-
Kingsquee
paradoxspiral, I thought box syntax was just sugar
-
Trangar
Box has always been a bit magical
-
Kinnison
Kingsquee: Vec::with_capacity(n), followed by .resize(n, 0) might be you best bet
-
Mutabah
`box foo` syntax allocates memory, then tries to write straigth into that (instead of making the value on the stack)
-
Mutabah
But, there's some underlying limitations to creating arbitary objects with `box`
-
Kingsquee
Kinnison, I'm actually making an abominably large struct, just used the array to test
-
Kinnison
aah :/
-
Arnavion
(in-place-expr would've solved this for the general case including boxes, but it was unreliable so it was removed)
-
Kingsquee
I guess some shenanigans with ptr::write might work
-
Kingsquee
Arnavion, 'unreliable'?
-
Arnavion
It didn't always do its job in unoptimized builds
-
Mutabah
Kingsquee: Well, `box foo` is effectively `{ let b = allocate(); ptr::write(b, foo); Box::from_raw(b) }`
-
Arnavion
which defeated its purpsoe
-
Kingsquee
because llvm?
-
Kingsquee
Mutabah, yeah, it's the 'allocate' part that I'm a little perplexed on right now
-
Kingsquee
is there a heap::allocate hiding somewhere
-
Arnavion
std::alloc::System or whatever it's called
-
Kingsquee
-
Kingsquee
nice, thanks
-
Arnavion
-
Arnavion
Huh, didn't realize GlobalAlloc had been stabilized but regular Alloc had not
-
Fr0stBit
Hi guys! Anyone using 'rodio' in rust for audio playback? I want to make an equalizer but i don't know how am i supposed to take the samples while the audio is playing
-
ejpbruel
i've opened an issue for the lifetime issue i mentioned earlier:
-
ejpbruel
-
user64
Is there a rust diacritics-aware crate for searching strings?
-
user64
Will nll handle `v.into_iter().map(|x| (x, do_something(&x)))`? Right now the compiler complains about x being moved before being referenced.
-
Arnavion
user64: Use {~crate unicode-normalization} to normalize the input and output to NFC, then substring
-
rustybot
unicode-normalization (0.1.8) - This crate provides functions for normalization of
-
Arnavion
-
user64
Arnavion: thanks.
-
jschievink
can you use gtk-rs to create a MenuModel? I don't see a way to construct one
-
Ploppz
trying to derive Deserialize on a struct, I get this error:
bpaste.net/show/d37355d8834a
-
_Vi
How much does each push to a rust-lang/rust's pull request cost in terms of CPU time? Is it appropriate to rely on auto checking and avoid lengthy local `x.py build` for small pull requests?
-
tazjin
is there a way to disable default-features for implicit dependencies?
-
_Vi
tazjin, "Implicit" means "transitive"?
-
tazjin
yes
-
Ploppz
oh just had to remove the trait bounds
-
_Vi
tazjin, Does adding them as direct dependencies with `default-features = false` work?
-
tazjin
yes, it does - but I'm wondering if there's some other way to do that
-
_Vi
tazjin, Make intermediate dependencies re-export necessary features and specify `default-features = false` themselves.
-
_Vi
tazjin, Like with clap and structopt. Structopt's default implies clap's default.
-
tazjin
concretely in this case, some of my dependencies use some of the async ecosystem, where eventually some crates depend on obscure things like support crates for fuchsia
-
tazjin
but I don't use any of the async dependencies directly and it seems like these features aren't propagated all the way through
-
tazjin
explicit deps it is, I suppose :) thanks _Vi
-
madalynn
hey
-
Trangar
hey
-
madalynn
I just checked and found out that core::intrinsics::type_id is stable over different compilations somehow. can I assume that this is really the case?
-
Moongoodboy{K}
madalynn: docs for me say it's consistent across /crates/, but not across /compilations/
-
madalynn
yeah okay fair enough
-
madalynn
the problem is I need a way to extract a unique identifier (could also be a string) for a given type that is stable over crates/compilations/compilers.
-
madalynn
would be nice if core::intrinsics::type_name had these guarantees
-
paradoxspiral
why do you need that?
-
Moongoodboy{K}
That seems difficult even in theory (see: the Ship of Theseus).
-
Moongoodboy{K}
(s,S,s,)
-
madalynn
i want to build a protocol on top of that guarantee. seems like I have to roll my own to keep it stable.
-
madalynn
it is mainly about function signatures.
-
madalynn
as long as the function signatures stay the same I want the same unique identifier
-
Lymia
The best approach is probably to ask the user to define a unique UUID explicitly somehow.
-
Lymia
Or something like that.
-
Lymia
I don't think there's a good way to do it otherwise.
-
madalynn
hmmm
-
Moongoodboy{K}
Oh that's easy then.
-
paradoxspiral
do proc-macros on functions get the absolute path?
-
Moongoodboy{K}
…well. It's easy if you can get a type -> id mapping with that property.
-
madalynn
Moongoodboy{K}: if I have something that is unique and stable I can always hash it to get an id
-
Moongoodboy{K}
Then you just hash something like "fn({:arg_id[0]}, {:arg_id[1]}, ..) -> {:ret_id}"
-
Moongoodboy{K}
…although those won't actually be unique(!).
-
madalynn
Moongoodboy{K}: yeah that is basically what I planned to do
-
madalynn
Moongoodboy{K}: why won't these be unique?
-
madalynn
okay, they are unique if you don't assume hash collissions
-
madalynn
hash collissions are okay and I just assume they do not happen for now
-
Moongoodboy{K}
impl Foo { fn bar(&self) -> Self { .. } fn baz(&self) -> Self { .. } } // these two methods have the same signature, so will have the same id under your scheme
-
paradoxspiral
that's why you also need the absolute path
-
Moongoodboy{K}
oh okay there you go
-
paradoxspiral
if proc-macros on functions do get the absolute path it'd be easy, then you can just hash the signature
-
Moongoodboy{K}
hash "fn {:path}({:arg_id[0]}, {:arg_id[1]}, ..) -> {:ret_id}"
-
Moongoodboy{K}
What about aliases and reexports though?
-
paradoxspiral
true
-
paradoxspiral
so you then need to canonicalize, which makes it much much harder :P
-
Moongoodboy{K}
Mmm
-
Moongoodboy{K}
proc macros with module system access when? :(
-
madalynn
-
madalynn
Moongoodboy{K}: two equal signatures having the same id is what I want
-
Moongoodboy{K}
Oh. Maybe you could use the hash of that.
-
madalynn
Moongoodboy{K}: as far as I saw there is no Hash impl for it
-
madalynn
oh damn there is
-
madalynn
this could be interesting
-
madalynn
i need to know if its type_id is stable across compilations and compilers
-
Moongoodboy{K}
…wait a sec. :P
-
Moongoodboy{K}
<paradoxspiral> why do you need that?
-
paradoxspiral
yeah i'm still not convinced^^
-
paradoxspiral
-
madalynn
but what does "globally" mean here? "A `TypeId` represents a globally unique identifier for a type."
-
Moongoodboy{K}
probably means across all crates in this compilation?
-
madalynn
but yeah cannot use it then
-
madalynn
Moongoodboy{K}: yeah maybe
-
madalynn
but coming back to core::intrinsics::type_name it should actually stay the same over crates, compilations and even compilers and should only change if the name of a type changes which is assumed to never happen
-
madalynn
so if I do not care about hash collissions I should be fine using it
-
paradoxspiral
don't rely on implementation details
-
j_ey
-
madalynn
can you explain what is an implementation detail for a type name?
-
j_ey
since I have a &mut to X and a & to X
-
Moongoodboy{K}
madalynn: docs don't say it's fully-qualified though
-
paradoxspiral
oh, type_name. read _id
-
madalynn
it is fully qualified as far as my tests go
-
madalynn
but yeah it is not specified to be
-
madalynn
that's ttrue
-
Moongoodboy{K}
j_ey: You modify the static while something is holding a reference to it. That sounds very dragon-waking to me
-
Moongoodboy{K}
References fully expect to not be mutated out from under.
-
j_ey
Moongoodboy{K}: yeah it's..not great
-
Moongoodboy{K}
j_ey: yeah I'm just gonna go ahead and assert that this wakes the dragon
-
j_ey
oh well, it's code I was writing for a friend, not my dragon :D
-
j_ey
(but really, just gonna suggest he uses a get_X function to do the unsafe/unwrap of a static mut Option<X>)
-
Moongoodboy{K}
j_ey: make sure that function is marked unsafe
-
j_ey
hmmm
-
j_ey
maybe there is a nicer solution overall, but I havent thought of it yet
-
Moongoodboy{K}
well, what is this static for?
-
j_ey
it's a global so they dont have to pass it around everywhere / clone this Rc theyre using
-
Trangar
j_ey: lazy-static and RwLock?
-
j_ey
lazy_static won't work because of the way it has to be initialised
-
Trangar
You can make it an Option<RwLock<RealFoo>>
-
j_ey
then you end up unwrapping everywhere
-
Trangar
Yes
-
Trangar
Which makes sense, what happens when you have a #[test] function that calls X.foo() ?
-
Moongoodboy{K}
wait like half the point of lazy_static!{} is to avoid Option for this stuff
-
paradoxspiral
^
-
paradoxspiral
with lazy_static you can just give a non-const fn as an initializer
-
Trangar
I think they want it to be initialized with data that's available in fn main
-
j_ey
^
-
Trangar
j_ey: I've done it before with unions, but honestly I'd just take the Option<RwLock<T>> route
-
j_ey
Im going to see if they can rewrite it so that the code is called from inside a lazy_static function
-
Trangar
It's bitten me more than the overhead of typing .unwrap()
-
Trangar
You could initialize it in the lazy_static and update the values from main
-
Trangar
Basically like you're doing in that example
-
paradoxspiral
j_ey: so the static is only initialized once in fn main, and not later changed?
-
j_ey
-
j_ey
I changed the example a bit
-
j_ey
I actually got a bit confused when I first wrote the example. the Foo struct is there just to deref to the static
-
Trangar
-
paradoxspiral
j_ey: so does the value need to be changed after it's initialized?
-
j_ey
paradoxspiral: no, i dont think so
-
j_ey
Trangar: thanks, will show that to them too
-
Trangar
That's the safe way of doing it
-
paradoxspiral
-
Trangar
Your unsafe way might work, but it might also break horribly and eat your family pet
-
j_ey
hm
-
paradoxspiral
also what i've done in a similar situation (a global once initialized Config) is just move the code out of main into the lazy_static initializer, no need for that workaround
-
paradoxspiral
-
j_ey
Im not sure if that can work for them, but I suppose they will give it a try
-
STD_ISBORED
Hi, I have rust setup on both my laptop and on my android phone via termux. I am looking for an IDE similar to codiad because I can't seem to get codiad to work on my phone. It works the first time and then I can't figure out how to start it again. What can I use instead? Anyone know?
-
Trangar
You have rust set up on your phone?
-
Trangar
I might have to try that...
-
paradoxspiral
imagine the compile times :p
-
Trangar
Can't be worse than my current build server :D
-
Trangar
Pretty sure my phone has more CPU
-
scoopr
ah, the warmth of rls in my pocket
-
paradoxspiral
lol
-
Yatekii
pub const CSW_RESERVED: u8 = 0x01000000; // rust does not complain aboutthis?
-
Moongoodboy{K}
eval: pub const CSW_RESERVED: u8 = 0x01000000;
-
eval
warning: constant item is never used: `CSW_RESERVED`
-
eval
-
Alexendoo
It didn't always IIRC, maybe you're on an older rust version Yatekii?
-
stephaneyfx
It's an error in Rust 2018 afaik
-
Yatekii
Alexendoo: pretty recent
-
Moongoodboy{K}
panicbit: why you no make eval put errors before wafningst
-
Yatekii
maybe it's not at that pass yet then
-
Moongoodboy{K}
panicbit: also gotta fix the ?edition thing (eval clearly submitted that code with edition 2018, but the link it posted doesn't have ?edition and thus defaults to 2015)
-
panicbit
Moongoodboy{K}: It's not trivial to do so
-
panicbit
Moongoodboy{K}: I've been requested the playground to support json compiler output
-
panicbit
to allow me to do the reordering
-
Moongoodboy{K}
ah, okay.
-
panicbit
words.
-
panicbit
Yeah, the edition stuff needs fixing
-
panicbit
Now that I'm sick and can't go to work, I may actually find the time
-
Moongoodboy{K}
Aww.
-
» Moongoodboy{K} pets panicbit.
-
panicbit
thank
-
jonimake
....waiting for file lock on build directory
-
jonimake
...5 mins later, still waiting
-
jonimake
*groan*
-
Phrohdoh
I am attempting to do some custom pretty-ish printing. Currently I am using `{:0>#2}` but I want that 2 to be dynamic (I have a u32 local I want the width to be), how can I do this? Do I have to use named print/format args?
-
rom
When a function generic over T requires many constraints on T, we can group them under the same Trait
-
rom
-
stephaneyfx
-
stephaneyfx
rom: This is similar to the dual From/Into from std
-
stephaneyfx
rom: The idea is to swap the type parameter and Self
-
rom
ok, this works, but I would have liked a version using conv: the fact that i32 is Conv<T> is an "intrinsic" property of my trait, so the client should not care about
-
rom
even with: "pub trait Constraints: Sized + Conv<i32> where i32: Conv<Self> {}", if in my function I use T: Constraints, it does not infer that i32: Conv<T>
-
blink
Given a Result<usize, usize>, how to "unwrap" its value without caring if it is Ok or Err?
-
stephaneyfx
blink: r.unwrap_or_else(|x| x)
-
blink
stephaneyfx: Lol! Thanks =)
-
Phrohdoh
wut
-
Phrohdoh
why would you want that?
-
stephaneyfx
-
Phrohdoh
But wouldn't you end up with the exact same result type?
-
stephaneyfx
You'd end up with an usize, not a Result
-
Phrohdoh
Ah ok
-
Phrohdoh
They don't care because it is likely the same value
-
Phrohdoh
for both T and E
-
nifker
its still not possible to impl trait for long arrays?
-
ldiamond1
I have a function that creates a reqwest client and passes it to a function which uses the client and the response. I want to test those functions. I'm unsure what the best way to mock reqwest is.
-
Moongoodboy{K}
jonimake: is there actually a cargo or rustc instance trying to do something in that directory?
-
Moongoodboy{K}
eval: format!("{:0>#len$}", 42, len = 7)
-
eval
"0000042"
-
Moongoodboy{K}
Phrohdoh: ^
-
Phrohdoh
Thanks I'll give that a go :)
-
Moongoodboy{K}
nifker: well, you can `impl<T> Foo for [T; 4096]`
-
Moongoodboy{K}
but you can't yet `impl<T, const N: usize> Foo for [T; N]`
-
nifker
Moongoodboy{K}: seems like many crate dont have this automatically implemented
-
Moongoodboy{K}
Don't have what automatically implemented?
-
nifker
[T; 0] to [T; N]
-
ldiamond1
Can I "attach" a trait to a struct that already directly implements the same interface without redefining the implementation?
-
dftxbs3e
ldiamond1: I guess it'd be better to move the code out in the trait entirely?
-
clueless_newbie
heio, anybody here ?
-
ldiamond1
dftxbs3e: it's not my code, it's reqwest
-
ldiamond1
They don't define traits for everything so I'm stuck defining it
-
dftxbs3e
ldiamond1: ah ok, well I don't think so that you can. It makes more sense and it's more consistent to move the code in the trait implementation. Try a PR! I'm sure they'll love it.
-
dftxbs3e
In the mean time, your dependency can be a git branch of yours\
-
Moongoodboy{K}
ldiamond1: not at the language level, but if the names and signatures are really the same, you can use a macro to trivially implement (such a macro might already exist)
-
Moongoodboy{K}
…and, yeah, for the mid to long term, actually implement the trait upstream
-
ldiamond1
Or am I doing it wrong?
-
ldiamond1
I use reqwest to make HTTP requests. I want to test my code against a mock.
-
ldiamond1
My idea was to create a mock that matches what I use, make it implement the same traits and simply replace it
-
ns1g94
hey, how likely is it that Rust's compile-time evaluation feature is seeing significant progress this year?
-
Edd-M
Anyone good with serde?
-
Edd-M
I don't understand why serializing an Option doesn't work here:
gist.github.com/vext01/838d9e589363327500e4bce3b32a4c74
-
Edd-M
serializing without the Option wrapping, as shown in commented lines, works
-
msmorgan
Edd-M: does rmp support nulls?
-
Edd-M
msmorgan: I assumed it did, but I guess not?
-
msmorgan
Edd-M: what sort of error do you get?
-
msmorgan
maybe it just doesn't support top-level nulls
-
msmorgan
but nulls inside of a structure would be okay
-
Edd-M
Ok, well I could do with top level option
-
Edd-M
Is there a better serialised format?
-
msmorgan
Edd-M: for what purpose?
-
Edd-M
msmorgan: stuffing things into an ELF section, eventuallly
-
Edd-M
btw, i tried pusing the Option inside another struct, the outcome is the same
-
Edd-M
struct Packet(Option<MetaData>)
-
msmorgan
Edd-M: it appears to support it
-
msmorgan
-
Edd-M
Note that my example uses only Some
-
Edd-M
this is werid
-
ns1g94
any ideas if Rust's const-eval functionality is moving a lot in 2019?
-
Edd-M
-
egregium
is there a hard reason for why lifetime elision in function definitions doesn't extend to 'where' clauses, or is that just something that hasn't been implemented yet?
-
msmorgan
Edd-M: that would do it
-
msmorgan
looks like it's not released yet
-
Edd-M
no
-
Edd-M
which is irritating
-
msmorgan
you could vendor the package in the meantime
-
msmorgan
or use a git version
-
Edd-M
or use a git hash
-
Edd-M
yeah
-
egregium
e.g. 'fn foo(&self) where &Self: IntoIterator' won't compile.
-
Edd-M
msmorgan: not sure I can use git
-
msmorgan
egregium: why not implement the trait for &'a Self
-
Edd-M
he's got several crates in the one repo
-
msmorgan
Edd-M: that works
-
msmorgan
you indicate it's in that repo and it finds the crate from the cargo workspace of that repo
-
kora
-
Edd-M
msmorgan: i see, thanks
-
egregium
msmorgan: because that's not the only method.
-
msmorgan
kora: Most of the time they're taken by value
-
msmorgan
in my experience
-
Edd-M
msmorgan: works
-
Edd-M
thankyou for your help :)
-
kora
msmorgan: so that would make the cloning explicit
-
msmorgan
egregium: for some reason [E0637] doesn't exist in the error index
-
msmorgan
egregium: but I assume that when using a reference as a type, you need to explicitly name a lifetime for that reference
-
silentk
What's a good primitive for some kind of shared event in Rust? Thinking along the lines of something with set and unset API
-
digital
there's a typo in the E0716 compiler error message, the word value is missing in two places:
play.rust-lang.org/?version=nightly…st=ce3e9ba20c4a65574387f66aa43f84f2
-
msmorgan
digital: perhaps they're using "temporary" as a noun
-
msmorgan
seems jargony though
-
wpage
I think it's pretty standard compiler/language jargon, though
-
digital
if it's a noun then it should always be a noun, in which case there are two "values" too much
-
msmorgan
fair point
-
msmorgan
you a copy editor?
-
wpage
-
digital
I'm not a copy editor
-
msmorgan
digital: in the error index the first use of the noun temporary is bolded
-
slabity-M
Anyone here use rendy yet? I'm trying to get it running but their examples don't seem to work
-
digital
msmorgan: hm okay
-
snek
how can i make a hashmap that accepts two different members of an enum as the key
-
msmorgan
snek: like, either or?
-
snek
msmorgan: so i'm making an interpreted language
-
snek
i'd like the keys of objects to be either a string type or a symbol type
-
snek
right now they're only strings
-
msmorgan
oh I see
-
msmorgan
but not simply any type at all
-
snek
which i get by lowering my Value::String(String) to just String
-
msmorgan
could you make a MapKey enum?
-
snek
i can't use Value itself as the key because its not hashable
-
msmorgan
and lower to that?
-
snek
how would that play with my Value enum
-
msmorgan
the same way the present string behavior does, right?
-
snek
so there's just be an extra layer of indirection for my string and symbol types
-
msmorgan
just have a way to try to convert to a MapKey
-
snek
oh have a separate type hmm
-
msmorgan
yeah, enum MapKey { Symbol(Symbol), String(String) }
-
msmorgan
and implement hash for that (or derive it)
-
snek
what is Symbol(Symbol) though
-
snek
Symbol itself is a Value
-
snek
so that would be circular
-
msmorgan
don't you have a Value::Symbol(Symbol) variant?
-
msmorgan
or is it Value::Symbol(String)
-
msmorgan
or something
-
snek
Value::Symbol(String)
-
msmorgan
okay then use Symbol(String) in MapKey
-
snek
where String is a symbol's "descriotion"
-
snek
description*
-
msmorgan
isn't there supposed to be some sort of opaque information in a symbol?
-
snek
isn't that just being a symbol
-
msmorgan
in JS, you could have multiple symbols with the same description, but they wouldn't be considered equal
-
snek
isn't constructing the symbol variant already doing that in rust
-
msmorgan
nope
-
snek
why the FUCK does rust have a lifetime on it then
-
msmorgan
huh?
-
msmorgan
calm down
-
snek
like
-
snek
`enum X { Y }`
-
snek
using `X::Y` gives me something with a lifetime
-
msmorgan
yes, values have lifetimes
-
msmorgan
lifetimes are erased at runtime
-
msmorgan
so you can't compare lifetimes
-
snek
no i mean
-
snek
if its just some thing that represents a lifetime
-
snek
enum member*
-
snek
downleveled to a number or something at compile time
-
snek
why does it have a lifetime
-
msmorgan
because values have lifetimes
-
msmorgan
for the purposes of the borrow checker et cetera
-
snek
can you borrow an i32
-
msmorgan
yes you can
-
snek
now that's messed up
-
salasrod
Well, stop using rust then snek
-
snek
lol
-
snek
but i'm trying to learn rust
-
Ploppz
is there a good plotting library out there?
-
msmorgan
read the book instead of jumping in with half-baked ideas
-
snek
i've read lots of the book
-
msmorgan
i can see that
-
snek
the book is useful for people who already know rust
-
snek
not for those two don't
-
msmorgan
-
msmorgan
now you might know enough to comprehend this chapter better
-
snek
so what should i do to make my symbols unique
-
msmorgan
add additional data to them
-
msmorgan
some sort of identifier
-
snek
increment an i64 or something?
-
msmorgan
that would work, yeah
-
msmorgan
if you're incrementing though, u64 would be better ;)
-
snek
indeed
-
msmorgan
unless the language has special symbols and you want to give them negative IDs for some reason
-
snek
i'm just used to calling everything not a float an integer from wasm
-
msmorgan
that's why I said Value::Symbol(Symbol) at first
-
msmorgan
because I assumed that the Symbol variant would contain a Symbol struct
-
msmorgan
snek: one of the reasons you might have had a misunderstanding about borrowing i32s and such, is that they're just a bit pattern
-
msmorgan
every i32 that's 00101 is the same as every other
-
msmorgan
right?
-
snek
well i'm just more used to thinking about things on the stack, like random numbers, as not having any lifetime
-
msmorgan
Rust has a trait that specifies this, called Copy. if a type implements Copy, the compiler treats it a little differently. instead of transferring ownership ("moving") when a value is passed without a borrow, it just makes a new copy of it
-
msmorgan
since all you need to do is copy the bits
-
snek
yeah i saw that
-
msmorgan
that's why i32 seems to behave differently than most user-defined types
-
snek
its an interesting way to describe the actual behavior of numbers though
-
snek
unless they actually are all heap allocated
-
snek
which i hope isn't the case
-
msmorgan
almost everything in rust is stack allocated, except memory that has to be dynamic
-
Yatekii
how do I say an associated type has to impl X?
-
faern
Yatekii: type Foo: X;
-
Yatekii
oh that was easy lol
-
Yatekii
thx
-
msmorgan
for instance a Vec stores its members in the heap since you won't know how many there are at compile time
-
msmorgan
but a program like `fn main() { let v = vec![1, 2, 3]; println!("{:?}", v); }`
-
msmorgan
will store the other information about v in the stack
-
msmorgan
including its length, current capacity, and pointer to the heap storage
-
snek
yeah that seems normal
-
msmorgan
depends on the language
-
msmorgan
it wouldn't be normal for Java
-
snek
java isn't a normal language
-
msmorgan
lol define normal
-
snek
not java or brainfuck
-
faern
That's not a very productive side-track if you want to get on with the real problem :)
-
viny
java is brainfuck with curly braces
-
snek
see viny gets it
-
msmorgan
okay C# then, reference types are allocated on the heap
-
msmorgan
and List<T> is a reference type
-
msmorgan
QED
-
snek
lol
-
snek
isn't c# also the thing with linq
-
snek
qed
-
msmorgan
yeah, linq syntax is weird
-
msmorgan
but the underlying methods are pretty standard
-
snek
beautiful static SYMBOL_COUNTER
-
msmorgan
just transformers for iterators
-
msmorgan
snek: are you using an AtomicUsize for that?
-
snek
no
-
kora
why doesn't a panic require a semicolon?
-
msmorgan
kora: if it's the last statement in your function
-
egregium
kora: it never returns and the compiler knows it, so it coerces the 'return type' into any type it needs to be.
-
msmorgan
yup
-
msmorgan
same thing with unreachable!() and unimplemented!()
-
kora
I see
-
egregium
and any function call to a function with the return type '!'.
-
snek
is there a way to define implicit conversions between types
-
snek
i tried to define a from trait but that didn't work implicitly
-
j_ey
there's Deref
-
j_ey
but not quite the same
-
j_ey
but not in general, no
-
egregium
snek: rust tends to avoid implicit conversions except for some special cases.
-
egregium
the From trait is the typical way to define conversions that you want other generic code to understand, but it's explicit.
-
blank_sl8
is it impossible to safely implement a doubly linked list?
-
prz
nope, it's quite easy actually
-
prz
but you have to understand lifetime and RefCell
-
prz
-
blank_sl8
so one way is owned, and the other way is reference counted?
-
prz
blank_sl8: yepp ... one way to see it. or RefCell which holds a straigth reference
-
blank_sl8
oh, refcell isn't reference counted, is it
-
blank_sl8
that was rc or something
-
prz
nope, for linked list you don't need reference count, yoiu know how many things hold it
-
prz
RefCell allows you to "borrow" dynamically @ runtime
-
emerent
RefCell? How would a node look like?
-
blank_sl8
so if i'm making a data structure (tree-like) that needs nodes to reference their parents, I would typically use a refcell?
-
prz
yes, one solution. let me dig something out
-
prz
-
prz
you like lists, that shows you how to do lists in rusts in all variants including what yuou ask
-
prz
funny book as well
-
emerent
the bad safe deque?
-
emerent
uses Rc
-
prz
yes, that gives you a Rc design
-
prz
-
curiousernestbri
Is C relevant nowadays?
-
prz
but the point is not in the solution, point is to erad the journey in the book
-
mr_wibble
hey folks, I am fairly new to rust and using it to build a cli. I am trying to talk to a single sign on service using hyper and getting this error "peer cert is valid, or was ignored if verification disabled". any idea? thanks
-
prz
that will teach you HOW to preoperly lay out stuff in Rust to be safe while taking the ownership concepts to only the degree complexity you need for Send+Sync+RefCell
-
prz
curiousernestbri: probably most running code on the planet is C these days
-
egregium
mr_wibble: that doesn't sound like an error message, it sounds like everything went fine.
-
mr_wibble
thats what i thought but its being caught by the ` .map_err` maybe code is wrong
-
mr_wibble
and with reqwest i get
mibpaste.com/aOQxaY
-
mr_wibble
hmm the code seems to work in a linux container
-
seanmonstar
negative error codes sounds like windows, so schannel
-
mr_wibble
@seanmonstar I am on a mac though
-
seanmonstar
oh that helps, wasnt finding that error in msdn
-
mr_wibble
i came across some random links with mentions of apple stuff with that error code
-
seanmonstar
"errSSLPeerAuthCompleted"? whys that an error XD
-
mr_wibble
-
seanmonstar
i cant actually comment what that error code is supposed to mean
-
sfackler
seanmonstar: IIRC that's used to tell secure transport to stop the handshake at that point and give you back control
-
sfackler
if you want to do your own processing of the peer certificate chain or whatever
-
sfackler
might be misremembering though
-
mr_wibble
do you know how to get around it @sfackler
-
sfackler
it's probably a bug in native-tls
-
sfackler
and/or security-framework
-
sfackler
we should just keep going when running into that
-
seanmonstar
what triggers it? ive not seen others reporting that error
-
sfackler
the server might be requesting a client cert?
-
sfackler
since it's an SSO thing
-
seanmonstar
doesnt security-framework interact with keychain? would options in there trigger it?
-
sfackler
-
seanmonstar
so they have a second status code besides errSecOk to mean errSecOk
-
FireMario
can main() in build.rs return Result<(), Box<Error>>, too?
-
FireMario
and ExitFailure etc
-
viny
why not
-
viny
its just a binary
-
viny
it can panic!(), too
-
sfackler
seanmonstar: ah right, it's returned if you enable break_on_server_auth:
kornelski.github.io/rust-security-f…mework/secure_transport.rs.html#188
-
sfackler
which you do to iirc handle custom trust roots
-
sfackler
-
mr_wibble
so is this intended behavior or something wonky with how apple handles things?
-
mr_wibble
and I guess a follow up is: is it possible to have native-tls use openssl instead of the apple one
-
sfackler
it is not
-
sfackler
it's a bug in something, either native-tls or security-framework?
-
mr_wibble
one thing to mention and not sure if its related is: i wrote this tool in go before and renegotiation was needed.
-
sfackler
ooooh
-
sfackler
that's probably it
-
sfackler
there's some other API call that we need to ignore that error from probably
-
patapon
does anyone know a short way to test if all elements in a slice are equal?
-
patapon
with iterators and stuff
-
sfackler
I was looking at the code and very confused about how this would be breaking in this way some but not all of the time in the handshake :P
-
seanmonstar
mr_wibble: if you wanted, you could try the rustls backend of reqwest
-
seanmonstar
in your Cargo.toml, change to `reqwest = { version = "0.9.9", default-features = false, features = ["rustls-tls"] }`
-
seanmonstar
i feel like i read re-negotiation is a non-goal of rustls tho...
-
mr_wibble
so in the rusttls readme the author says there is no support for Renegotiation.
-
mr_wibble
`The following things are broken, obsolete, badly designed, underspecified, dangerous and/or insane. Rustls does not support:`
-
seanmonstar
ah then nevermind :)
-
mr_wibble
cool that you can do that with cargo though
-
sfackler
mr_wibble: I think you'll want to file a bug on security-framework - it probably needs to internally ignore that error coming out of read or write or something like that
-
egregium
patapon: fold() could probably do it reasonably neatly.
-
mr_wibble
is the history of this chat saved somewhere?
-
egregium
mr_wibble: it's in the topic.
-
egregium
-
mr_wibble
-
mr_wibble
thanks
-
mr_wibble
@seanmonstar @sfackler let me know what i can do to help debug
-
seanmonstar
mr_wibble: best would be to file an issue on the security-framework repo, including the error and that its using renegotiation
-
seanmonstar
if theres a way to reproduce it without needing any secrets from you, even better
-
GreenJello
I have an enum that implements Display... how can I impl serde::Deserialize for it, where it serializes to what format!("{}", self) would return?
-
dtolnay
-
GreenJello
I got my thoughts mixed up, but this looks like what I need, thanks!
-
lpg
kyren: Has anyone done any proc macro binding nonsense for rlua yet?
-
kyren
lpg: not that's up-to-date, it's actually on my near term TODO list
-
silentk
I need a value to be consumed and allowed to die. Can I just pass it into a function to kill it?
-
j_ey
drop can do that
-
lpg
also amazing work on rlua, this is fantastic
-
kyren
lpg: I'm not sure exactly what to call the trait, because people seem to get easily confused about conversion between structs <-> tables and structs <-> userdata, I'm almost certain once I write it to get questions about how to do proc-macro userdata conversion, which I'm not sure is even possible or sensible
-
kyren
lpg: oh thanks!
-
kyren
lpg: is it similar to your bindings system for Lua 5.1?
-
lpg
kyren: there's no semblance of safety in it and the bindings are mostly giant C macro invocations, but it's fairly convenient at least
-
egregium
silentk: if you're not getting the value as a function argument you can also just wrap the code that creates and uses it in a { } block and it will be destroyed at the end of it.
-
egregium
though that isn't always feasible when you have other variables declared after it that depends on the value.
-
kyren
lpg: I'm always interested in what other people have done because there are a bunch of really hard decisions that you have to make when writing language bindings in Rust, and I'm not convinced all of my decisions in rlua are the right ones, especially around ToLua / FromLua trait design and function types
-
kyren
lpg: if you wanted to make it safe, you might have an easier time because Lua 5.1 doesn't have __gc metamethods, right?
-
lpg
kyren: it does have __gc, but only for userdata, and also we turned them off because it was a huge sandbox escape hatch lol
-
lpg
kyren: the ToLuaMulti implementation for all the tuples in rlua made several people laugh nervously that I showed, so that was awesome
-
kyren
right, I forgot it was available but only for userdata
-
kyren
lpg: are they bad haha?
-
naftulikay
I'm currently working on a PR to rustup. `cargo build` works but it doesn't produce an actual rustup binary, only a rustup-init binary. I'm looking through .travis.yml and others to try to see how to produce the rustup binary, but no luck so far. Does anyone know how to build the rustup binary?
-
lpg
kyren: I'm not sure how else you'd solve the problem, heh
-
kyren
me neither, all of rlua was a goddamn bitch and a half
-
lpg
Lua projects I've worked on that specialize arg length/return length usually go out to 5-6, I think that's the limit on LÖVE's event loop stuff
-
j_ey
naftulikay: hm, what about cargo build rustup
-
naftulikay
build doesn't take an argument? it complains that it found an argument it didn't expect
-
j_ey
what about cargo run rustup
-
lpg
kyren: You mentioned proc-macro driven userdata stuff being difficult/not possible, that's what I was imagining to try, what issues do you see with it?
-
naftulikay
nope, same thing
-
naftulikay
`Found argument 'rustup' which wasn't expected, or isn't valid in this context`
-
naftulikay
I'll ask on users.rust-lang.org
-
kyren
lpg: sorry I was being a bit vague, I'm sure it's possible (and even pretty easy) to do a proc-macro for table conversion, and I'm sure it's possible but kind of hard to do a set of proc-macros for userdata + methods
-
lpg
the fact that the struct def + impl block are separate blocks is pretty inconvenient
-
kyren
lpg: but I've been asked for stuff that's... I guess not impossible but reeally magical and problematic before, like __index based access to userdata *fields*, which okay I guess that also *might* be possible, but it can kind of get insane
-
kyren
I haven't really actually thought about it extremely deeply yet
-
kyren
and a lot of the problems are the same problems that wasm-bindgen is solving
-
lpg
it's not that bad if you construct a new userdata wrapper around the type for every __index :D
-
lpg
at the cost of making hashing on [userdata.x] really inconsistent and scary, but that's the tradeoff we made
-
kyren
I gueesssssss but they might not even be Clone
-
naftulikay
-
egregium
naftulikay: where in the crate is the source code for it (the main() function) ?
-
lpg
kyren: all of our types are either referentially consistent and mutable (instances) or an immutable value (everything else), which is handy
-
j_ey
naftulikay: do you have rustup-cli
-
j_ey
?
-
j_ey
oh sfackler replied on the web
-
j_ey
-
naftulikay
yes, this solves my problem 👍
-
blank_sl8
where is the `ref` keyword in a `match` statement documented?
-
blank_sl8
-
jebrosen
-
jebrosen
-
blank_sl8
so, is there a more up-to-date way i could have written teh playground?
-
blank_sl8
without using .map or anything
-
jebrosen
Some(string_cheese) without `ref mut` appears to work
-
emerent
yeah, just leave out ref mut
-
blank_sl8
so it magically detects that it doesn't need to take ownership of string_cheese?
-
jebrosen
Yes
-
blank_sl8
will that ever fail and make ref/ref mut necessary?
-
prz
yeah, you don't need the ref mut here
-
prz
you want to _move into_ the string inside
-
silentk
-
prz
I'm mildly astonished you don't need a mut though and it inherits the &mut
-
jebrosen
blank_sl8: In specific circumstances maybe, but there was a big effort to make ref/ref mut unnecessary in patterns
-
silentk
My gist linked above works. Curious if it
-
blank_sl8
ok, i'll try to avoid it then. Thanks!
-
stephaneyfx
-
silentk
curius if if looks awful at first glance
-
prz
aha, when you add mut it moves in and I get the xpected "cannot move out"
-
stephaneyfx
blank_sl8: Just in case you want to know more
-
prz
it seems to infer the ref mut on the pattern now. That's new ;-)
-
blank_sl8
i think i'll read that a bit, i'm reading some article someone linked about linked lists and they are using ref a lot
-
egregium
the new 'smart' ref-less patterns are really confusing.
-
prz
egregium: well, if they really work ;-)
-
prz
blank_sl8: basically, simple rule, if compiler throws at you error[E0507]: cannot move out of borrowed content
-
prz
you need ref ;-)
-
egregium
it's not that new, by the way, it's a couple of months old.
-
ted
i dunno, having rustc error on you because you forgot a `ref` was pretty annoying
-
prz
ted: but it forced you to think what the hell you're trying to do ;-)
-
emerent
blank_sl8: it's not magic, it just propagates the &mut into the inner bindings
-
ted
eh
-
ted
there are enough places where you have to think about ownership where it actually matters :)
-
prz
ted: one of the biggest performance killers is implicit Clone and ending up moving into stuff that forfces Copy when you really need a ref
-
prz
ted: agree here ;-) I'm not unhappy, I just say it's new ;-)
-
prz
sorry, I mean "implicit Copy"
-
ted
yeah, that's fair
-
blank_sl8
"segmentation fault" induces the most thinking about what you are doing imo
-
prz
which rust never gives you ;-)
-
egregium
as in 'what am i doing with my life?'
-
egregium
'why aren't i using only safe rust?'
-
prz
egregium: yepp, as in, why am I still doing C bean counting if I can be lazy and let compil.er in rust do it ;-)
-
prz
egregium: Rust is for the good programmers beacuswe all good programmers are "lazy" and try to not do beanc counting but work on interesting stuff that computers cannot do for them ;-)
-
npmccallum
What is the memory layout of enums? Does the discriminant always appear first?
-
ted
hah
-
egregium
npmccallum: not defined, as far as i know.
-
Arnavion
npmccallum: Unspecified
-
ted
npmccallum: any data type with repr(rust) (the default) is unspecified
-
egregium
npmccallum: the discriminant doesn't even exist as a separate field in some cases.
-
egregium
Option<&Foo> is the same size as &Foo, for example - the forbidden 0 value for the reference is used to encode 'None'.
-
ted
-
npmccallum
Can I use something like repr(C) to get a defined layout?
-
Arnavion
For enums whose variants don't have data, yes
-
egregium
or repr(u8) etc to get a certain size.
-
Arnavion
What problem are you trying to solve
-
npmccallum
What I really want is repr(u32) where the layout is u32 first and data afterwards.
-
Arnavion
Why do you need that
-
ted
-
ted
but i don't know if you can actually use that yet?
-
npmccallum
Arnavion: I'm trying to match the memory layout of data coming from firmware.
-
ted
there might be some way to actually do that
-
Arnavion
For FFI you cannot have enums with data
-
ted
Gankro wrote that rfc, you might ask them
-
Arnavion
Make a struct that has a repr(u32) enum and a union of the fields after it
-
npmccallum
ok
-
Gankro
npmccallum: do you want the payload to be aligned as if its struct { u32, field1, field2... } or struct { u32, struct { field1, field2, ... } }
-
npmccallum
The latter.
-
npmccallum
I assume I can use an attribute to align this type to a page boundary?
-
j_ey
there is repr(align), but I cant remember all the detais
-
Gankro
-
Gankro
-
Gankro
which I believe is what you want
-
j_ey
"If the enum has fields, the effect is similar to the effect of repr(C) in that there is a defined layout of the type."
-
j_ey
about repr(u*)
-
Arnavion
Gankro: They said they want tag + union-of-fields, not union of tags+fields, so I think they want G
-
Gankro
oh oops, misread :)
-
Gankro
yes
-
Gankro
repr(C, u32) is what you want
-
j_ey
-
Gankro
#[repr(align=X)] does alignment
-
j_ey
this seems to suggest that repr(C, u32) would be the same as repr(C) if it has fields
-
Gankro
j_ey: I wrote the RFC, the compiler impl, and mantain the docs you linked :)
-
ksynwa
Can someone help me understand the matching in this code?
pastebin.com/raw/bqYbyMbv
-
Gankro
plain repr(C) is sugar for repr(C, "whatever an enum is sized to be in C on your target hopefully")
-
npmccallum
Am I able to detect an invalid enum value in the case of FFI?
-
j_ey
Gankro: no doubt, but I'm trying to understand the text
-
ksynwa
Particularly, I don;t know what `m if is_yelling(m)` means inside the match bracket.
-
egregium
ksynwa: 'if is_yelling(m)' is an extra check that means that the branch will only be executed if is_yelling(m) returns true.
-
j_ey
Gankro: from my reading it doesnt sound like repr(u*) affects the size, if repr(C) is also there
-
npmccallum
Gankro: tag + union of structs
-
npmccallum
Gankro: so I want repr(C, u32)?
-
nifker
does Duration support an infinite time?
-
ksynwa
egregium: is `m` an alias of message.trim() there?
-
Gankro
npmccallum: yes, i'm not sure what you mean by "detect"?
-
egregium
ksynwa: 'm' is an identifier pattern that matches anything and names whatever it matched 'm' in the context of that branch.
-
j_ey
nifker: doesnt look like it
-
egregium
ksynwa: so in your case it will bind to the return value of message.trim().
-
ksynwa
egregium: I get it now. Thank you very much.
-
Gankro
j_ey: i mean, just look at the cbindgen examples I linked, the different sizes affect the output (and we use those results in firefox)
-
npmccallum
Gankro: If I have an enum repr(u32) and I pass a reference to it to a FFI function where the FFI function fills in the value, it is possible that the FFI function fills in a value which is not represented in my enum.
-
npmccallum
Gankro: I'm not sure the best way to handle that situation.
-
j_ey
Gankro: sure. I still feel like the docs don't explain that well
-
Gankro
npmccallum: sadly it's Undefined Behaviour if they set a bogus value. You can use the equivalent struct-and-union repr while you're not sure if it's properly initialized, do the check, and then cast to the nice enum form afterwards
-
npmccallum
Gankro: this is a different case
-
npmccallum
Gankro: I don't have data in the enum in this case.
-
Gankro
g2g meeting
-
egregium
npmccallum: i think it doesn't matter whether it's a c-like enum or one with data in it, an invalid value for the discriminant is still undefined behaviour. you'd have to just read it as a u32, check it, and then convert it to the enum type if you want to avoid that.
-
talchas
yes
-
npmccallum
Is the discriminant value well-defined for enums with data?
-
npmccallum
(i.e.: starts at zero and increments by one)
-
Gankro
npmccallum: it matches the platforms C convention
-
Gankro
which for all the ones I know is 0,1,2,...
-
talchas
npmccallum: it's most likely unspecified unless you repr(C) it
-
talchas
if you do, it is
-
Arnavion
Hmm, for some reason `cargo build -p foo` within a workspace works, but `cargo build -p bar` for another crate in the same workspace fails with "can't find crate for `failure_derive` which `failure` depends on". Both foo and bar depend on failure. Any ideas?
-
talchas
(in practice it's likely the same as the repr(C) specified one because there's no reason for it not to be, at least so long as there is a discriminant at all)
-
Arnavion
Obviously failure_derive is there in the lockfile, and `find -name '*failure_derive*'` finds files for it under target/debug (from the initial successful build of foo)
-
sunset
Hello
-
sunset
how can I use std::io::set_print on stable rust? I really need it and don't want to be forced to use nighttgly
-
sunset
thank you
-
sfackler
you can't
-
sunset
is there a workaround?
-
sunset
this is stable right?
doc.rust-lang.org/beta/std/panic/fn.set_hook.html ? there is no equivalent for print?
-
sunset
or it's unstable as well?
-
sfackler
panic::set_hook is stable
-
sunset
but I really need the same for stdio
-
sunset
isn't it possible to do it? even if it's unsafe?
-
j_ey
can you do it with some hacky to close and redirect fd?
-
sunset
unfortunately I am not under linux I am under wasm
-
sunset
not sure how it works with actuual fd
-
sunset
setting the Write in set_print looks the cleanest to me
-
sunset
Looking at this there is a LOCAL_STDOUT var
doc.rust-lang.org/beta/src/std/io/stdio.rs.html is it possible to replace it via unsafe?
-
j_ey
no
-
sunset
surely there must be a way?
-
talchas
you could try and alias it via a no_mangled name using the mangled name of that symbol
-
j_ey
is this so you can redirect println! to console.log?
-
sunset
yes
-
talchas
but libraries have a hash in it iirc so it would be terrible
-
j_ey
talchas: yeah.. I didnt really want to suggest that, but was one of the options I thought of :)
-
talchas
and then just use nightly
-
sunset
how do you do that? I don't even understand what that means
-
sunset
I would prefer not to use nightly, I had issues with nightly
-
talchas
it would be even less stable than nightly, in that it would be guaranteed to break every time you changed rustc version
-
sunset
even on stable I found issues in the compiler for what I was trying to do and had to make a bug report
-
sunset
how do you alias a function? you mean alias the function that println! uses internally?
-
j_ey
ignore that suggestion
-
sunset
:(
-
viny
yes, just dont
-
sunset
isn't it possible to get some pointer somewhere and just replace LOCAL_STDOUT?
-
talchas
I mean create an extern { fn the_mangled_name_for_set_print(args stuff); }
-
talchas
don't actually do this though, yes
-
mib_7lyyow
Hi, as my rust project is getting bigger, compilation time is shooting up. Only solution which I came across is to divide project into multiple crates, which helped a bit. But problem is everytime, I change something in a crate, all the dependent crates get rebuilt.
-
talchas
and anything else would be equivalently terrible and breaking
-
thavlik
Hi folks. What syntactic sugar is there for turning an iterator that yields (String, String) into a HashMap?
-
j_ey
thavlik: collect?
-
j_ey
but it's not syntax sugar
-
talchas
thavlik: .collect::<HashMap<String, String>>()
-
Yatekii
hmm is there smth like map() on an iterator that also returns the previous element?
-
thavlik
talchas, much appreciated
-
sunset
honestly it seems severely constrained that rust doesn't allow me to do this especially since I really need it
-
mib_7lyyow
Is there a way to fool its dependent crates that nothing has changed in parent crate, and make them use the latest crate using dynamic linking?
-
viny
Yatekii, no but you can .peek()
-
j_ey
sunset: the point of the unstable features is so that they're not exposed to stable builds
-
Phrohdoh
Which of
danielkeep.github.io/tlborm/book/mbe-macro-rules.html#captures do I want for to be able to do `Foo(baz)` where `Foo` is a variant of a specific enum? (this macro will only use this single enum type)
-
Phrohdoh
> ($start:expr , $end:expr, $tok:stmt) => { SpannedToken::new(ByteIndex($start), ByteIndex($end), Token::$tok) };
-
Phrohdoh
> tok!(1, 1, Ident("^foo")),
-
Yatekii
viny so you say I should first call peek() to get the current one and then next(9 to get the next one?
-
sunset
j_ey: but it's been unstable for years and hasn't changed, and it's being used internally by cargo test
-
j_ey
-
sfackler
sunset: it's unstable because it's not clear it should exist at all
-
j_ey
oh that looks like it needs nightly
-
talchas
Phrohdoh: it would have to be "$variant:ident($arg:expr)"
-
Phrohdoh
ah okay so I'd need multiple to work with data-holding variants and data-less ones
-
Phrohdoh
thanks
-
sunset
j_ey: but that means you have to import that macro instead? or it overrides it
-
talchas
eval: enum Foo { Bar } Foo::Bar()
-
eval
error[E0618]: expected function, found enum variant `Foo::Bar`
-
eval
-
sunset
it seems like a valid use case for me sfackler , and other languages I know allow you to do it
-
talchas
eval: enum Foo { Bar } Foo::Bar{}
-
eval
error[E0277]: `main::Foo` doesn't implement `std::fmt::Debug`
-
eval
-
talchas
eval: #[derive(Debug)] enum Foo { Bar } Foo::Bar{}
-
eval
Bar
-
Phrohdoh
talchas: worked perfectly, many thanks
-
talchas
Phrohdoh: so you can use the {} syntax for all three types of enum/struct, but not the () syntax
-
Phrohdoh
I don't follow
-
Phrohdoh
Foo{Bar} ?
-
j_ey
sunset: no-one is arguing with that
-
talchas
Phrohdoh: Foo::Bar {} is valid for no args, and Foo::Bar { 0: arg } is valid for a 1-arg tuple variant
-
talchas
but I'm not actually sure this is useful to you, and it's probably easier to just have two macro variants
-
Phrohdoh
Right but not for Foo::Bar(baz), right?
-
Phrohdoh
yeah the two variants seems to work fine
-
talchas
one for "Bar" and one for "Bar(expr)"
-
Phrohdoh
yep
-
sunset
j_ey: it looks like wasm-glue also uses set_print? so it wouldn't work on stable either?
-
j_ey
sunset: correct, I followed up with that
-
j_ey
sunset: when did you last use nightly?
-
j_ey
it's pretty stable usually. and you can find a stable one and just continue to use that
-
sunset
I think it was more than 6 months ago, and my library has been stable since then
-
sunset
I would regret to move it to nightly just becasue of this
-
j_ey
maybe you should try push for it or something, to be stabilized
-
sunset
well I don't have my hopes up, I don't have any influence, and that might take months no?
-
j_ey
you can try ask on one of the other forums, but I dont think there's a way you can hack this
-
sunset
This exists for years
rust-lang/rust #31343
-
Coylabe
tl;dr which exercise should I give to someone who is convinced that he is The Omnipotent God Of C, and that any language that tries to have memory safety as a design goal is useless?
-
Coylabe
(I could describe the situation more, but that's the gist)
-
Phrohdoh
Coylabe: You can't convince someone with that mindset of anything.
-
Phrohdoh
IME
-
sunset
I actually knew a guy (my uni professor) that was so disciplined he could code stuff without compiling and even syntax coloring
-
Phrohdoh
They've already decided they know everything and anyone who disagrees is wrong.
-
sunset
he once won a bet by coding I think a 2d game clone, forgot which with the right to compile only twice to check for his errors and won
-
sunset
such people exist Coylabe even if rare
-
Coylabe
I was thinking of something like "Code a program according to those specifications, then" and see if he makes it or not.
-
Coylabe
Oh, I'm not saying the possibility is zero! I don't think it's higher than 0.5%, but it's not zero.
-
sunset
evne the woman that made the original nasa moon ship program and such coded most of it on paper first
-
sunset
it is possible Coylabe to write correct programs in C, even without the help of the compiler, but it's much harder to do so, and much error prone
-
Coylabe
Yes, which is why I'm curious to see if he can do it.
-
sunset
what rules? he can use a compiler as much as he wishes and syntax coloring?
-
wpage
something with asynchronous parallel consumers and producers
-
wpage
and reads a file format
-
wpage
when he's done, run it through a fuzzer
-
Phrohdoh
Coylabe: Ask them to build whatever you're building. Free labor! :D
-
wpage
honestly, parsing just about any file format, and running the parser through a fuzzer will break it
-
Phrohdoh
as a "challenge" of course :)
-
sunset
not if it's written in Ocaml wpage
-
wpage
sunset: I thought we were talking about a C developer who swore he could write anything safely in C without help from the compiler or language
-
Ploppz
you can copy a Box, right? But then when is the memory deallocated?
-
Ploppz
or can there be only one owner of a Box?
-
j_ey
you cant copy a Box
-
sunset
I think you can with to_raw_ptr or how it's called
-
Ploppz
ah Box::clone copies the contents?
-
j_ey
clones
-
Ploppz
ok thanks
-
sunset
I forgot a bit the apis, but you can do many things if you convert rust stuff to ptrs
-
sunset
it's pretty straightforward
-
Phrohdoh
Can I get `cargo test` to print out the `ignore` reason?
-
Phrohdoh
(for each ignored test)
-
Ploppz
in a library/crate, I will use failure I guess. But is it ok to bail!("some textual error message") or should I aim to have enums only?
-
sunset
j_ey: can't you make a new rust release where it's possible to use the feautures I need from rust stable?
-
Phrohdoh
...wat
-
j_ey
aka nightly
-
sunset
or add levels to experimental feautures? like somes can be used from stable but are discouraged? like they work but can dissapear vs completely experimental
-
Phrohdoh
j_ey: cmon release new rust ;)
-
Phrohdoh
sunset: that level *is nightly*
-
sunset
there is a difference between something that might disssapear as in api not stable vs feauture not stable
-
sunset
set_print has been the same for 3 years basiclaly, I should be able to use it
-
j_ey
sunset: go complain on the issue
-
sunset
Phrohdoh: there is a difference in stability or safety between set_print that is used by cargo test, hasn't changed for years, and might dissapear vs a really experimental feature
-
sunset
I should be able to use once
-
Phrohdoh
Not with the way Rust is released currently.
-
j_ey
go make an rfc for it
-
Phrohdoh
^
-
sunset
can't someone add a new field to unstable to say like level of unstableness? and allow a low level to be used tin stable with a warning? such as set_print for example?
-
Phrohdoh
Someone *could* sure.
-
sunset
when I mean someone could I meant couldn't like j_ey do it?
-
Phrohdoh
But it isn't just adding a new line and calling it done.
-
j_ey
but it requires rfc etc
-
j_ey
sunset: why me lol
-
sunset
well removed the #unstable is just one commit
-
Phrohdoh
sunset: *you* could do it
-
sunset
I am not really familiar with the rust code, it might take me years to do it or something
-
snek
rust code is scary
-
sunset
I mean I could just remove the #unstable sure, but doing the other suggestion might take too much time
-
Phrohdoh
sunset: Doing things correctly takes time.
-
sunset
also last time I looked at the rust code there were parts that looked really cryptic, I don't think it's well written
-
snek
rust will definitely get in your way though
-
snek
the only question is if you value that
-
sunset
I am really upset, everytime I try to do something in rust things get in my way, this week was full of frustrations
-
snek
same
-
Phrohdoh
sunset: It'll be like that for a long time, IME.
-
sunset
it's been more than 5 days I've been waiting for someone to fix the compiler bug I've found and nobody did
-
sunset
can you do it j_ey ?
-
j_ey
no
-
snek
being able to store things at known offsets in allocated memory and cast around
-
snek
i miss that
-
Phrohdoh
are we being trolled?
-
sunset
j_ey: can you at least take a look at it?
-
Phrohdoh
sunset: Why have you latched on to j_ey?
-
j_ey
sunset: I dont work on the rust compiler
-
sunset
who works on the rust compiler? do you Phrohdoh ?
-
Phrohdoh
Nope.
-
sunset
:(
-
j_ey
but you realise this is an open source compiler, 5 day isn't *that* long for a bug to be open
-
sunset
but it's being supported by Mozilla, actual employees work on it
-
Phrohdoh
There are other priorities I'm sure.
-
Phrohdoh
Just because a bug is opened doesn't mean people drop everything and fix it.
-
sunset
so it might never be fixed?
-
j_ey
sunset: what was the github issue number?
-
sunset
-
sunset
can you fix it snek ?
-
j_ey
that was 3 days ago
-
Phrohdoh
sunset: people are *actively* commenting on it
-
j_ey
and people have been commenting on it
-
snek
i started using rust a week ago
-
sunset
oh? for some reason I thought it was 5 days
-
Ploppz
time goes fast when you're having fun :)
-
snek
sunset: give it some time, nothing is more annoying than people being upset when oss contributors don't move fast enough
-
sunset
it wasn't much fun for me, I had to stash my changed cause I couldn't continue
-
snek
you could always fix it yourself
-
sunset
unfortunately all my 3 ideas that I have been thinking about have been shut down for various reasons
-
talchas
I mean, what you have won't compile
-
Ploppz
mhm I understand
-
sunset
the effort I'd have to put into understanding sufficiently and try to fix it would be collosal
-
talchas
the fact that you're getting an ICE rather than a proper error message is a bug obviously, but I think the correct code would compile
-
sunset
It would most likely take much more time than waiting for someone to fix it
-
Phrohdoh
sunset: everyone starts somewhere.
-
j_ey
sunset: did you read the comments and what talchas just said?
-
snek
i learned c++ by contributing to node.js core
-
sunset
talchas: wouldn't compile? why not?
-
Phrohdoh
It has been made clear that people are commenting on it (and thus looking at it).
-
talchas
sunset: you have Fn() -> SomeTrait, aka Fn() -> dyn SomeTrait
-
talchas
you can't return an unsized type
-
sunset
so it's impossible to do that at all in rust?
-
sunset
can I return a reference instead or something?
-
Phrohdoh
To return an unsized type, yes.
-
talchas
and yeah, the simplified version posted on the bug compiles if that's fixed
play.rust-lang.org/?version=stable&…st=56be12fcfe701c0079690d48c4e1e1ff
-
talchas
most of the time it would need to be a Box<dyn Trait> rather than a reference
-
talchas
but yes
-
Ploppz
sunset: you can box it for example. Fn() -> Box<SomeTrait>
-
sunset
and can I take stuff from the Box?
-
sunset
in my case I need to call stuff on the box
-
Ploppz
you can use Box<SomeTrait> as if it was SomeTrait
-
snek
you can deref a box
-
Ploppz
yeah no problem
-
sunset
is it possible to mutably get stuff from the box
-
Phrohdoh
Have you tried using Box yet? (and then using the contents)
-
talchas
sunset: given Box<dyn Trait> you can call any of Trait's methods on the Box that don't have "where Self: Sized" attached
-
sunset
instead of a box can't I use a * or something?
-
sunset
I don't want to write closures that return boxes seems really not that clean to me
-
Phrohdoh
sunset: Honest question... have you read the Rust book?
-
sunset
err, can I not answer that?
-
Ploppz
Box is the cleanest option I think. Box is basically dynamically allocated memory, nothing fancy
-
talchas
ie, given x: Box<dyn JsSerializable> that yo umentioned in the bug, you can just do x.size() and x.ser(&mut cursor)
-
sunset
yes but the closure is not that fancy, and have to do Box::new at the return
-
Ploppz
it's what you use where you would in other languages use pointers, in my understanding
-
sunset
doesn't look cool
-
Phrohdoh
-
Phrohdoh
Please read it.
-
Phrohdoh
> doesn't look cool
-
Phrohdoh
Like, visually?
-
Phrohdoh
Or is there something deeper with Box you don't want in your program?
-
snek
what is JsSerializable
-
sunset
but that means someone has to write | val| { ... return Box::new() } it's not aestetical at all
-
sunset
it's a trait snek
-
snek
for what
-
Ploppz
you could return a reference &... but then you have to get your lifetimes right (i.e. the value must live long enough)
-
snek
i'm curious about the project
-
Phrohdoh
snek: Probably something to do with Neon
-
sunset
to serialize a rust value to js, currently it works for primitive types, strings and some other types
-
Phrohdoh
-
j_ey
sunset: use Box
-
snek
i thought neon was unmainained
-
sunset
-
Phrohdoh
snek, why did you think that?
-
Phrohdoh
Last commit Jan 3rd
-
snek
dunno
-
snek
obviously i'm wrong
-
sunset
can I return & instead of a box?
-
Phrohdoh
sunset: If you don't want to use Rust because the syntax is visually unpleasant to you... I'm not sure what help we can give.
-
j_ey
sunset: probably not
-
talchas
sunset: what I'd recommend in that case is something like fn register_callback<T:JsSerializable,F:Fn()-> T + 'static>(f: F) { actual_register_callback(move || Box::new(f()))
-
sunset
it's not that the syntax is unpleasant for me, I'd rather someone write a closure that does return 3; rather than box it
-
sunset
it doesn't look like clean code to me to force the user to box it
-
Phrohdoh
This is about ownership though
-
talchas
ie, you can make the function that registers the callback be generic over the return type, and then box it in there
-
Phrohdoh
You don't have to box it just for the hell of it, there is a reason.
-
talchas
eval: trait Trait {} fn foo(x: impl Fn() -> impl Trait) {}
-
eval
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
-
eval
-
sunset
talchas: I will think about that, but that would make like n versions for the function no? one for each impl I have?
-
sunset
I have quite a bit of them
-
talchas
sunset: in terms of compiled code, sure, but it would also likely be inlined
-
talchas
and would just result in the same code as if the user had written the Box::new
-
sunset
I see, thank you, I will look into doing that next time I work on it
-
lpg
So a gigantic amount of my build time with Cargo is spent outputting the progress bar because ConHost is slow on Windows
-
snek
is there an alternative to using AtomicU64
-
talchas
rip
-
lpg
`time cargo build` with no changes takes around 2677ms on my project with lots of dependencies
-
snek
building nightly kills my editor tooling
-
lpg
`time cargo build 2>/dev/null 1>/dev/null` is only 480ms
-
talchas
lpg: wow
-
lpg
maybe I'm messing something else up, but this isn't incredibly surprising to me
-
talchas
snek: outside of "use atomicusize and assert 64-bit" and "use Mutex<u64>", no
-
snek
are either of those things worse
-
talchas
I suppose actually you could write asm wrappers and link to those
-
snek
lol
-
talchas
you'll get worse optimization and have to do it on every 32-bit platform you care about but it would certainly work
-
lpg
screenshot from my terminal:
i.imgur.com/saiuP2A.png
-
snek
so if i want a static mutable u64
-
snek
as a counter
-
snek
i'm just sol unless i use nightly
-
talchas
yeah, I'm not going to defend atomicu64 still being unstable
-
Ploppz
lpg: just to be sure, you did modify the suorce between compiling?
-
lpg
no, that's with no changes
-
talchas
other than that it looks like it's finally going stable I think?
-
lpg
all of those runs were back-to-back
-
sfackler
it'll be stable in 1.35
-
sfackler
and just not defined on platforms without 64 bit atomic
-
sfackler
s
-
Ploppz
but then the compiler won't really do anything IME?
-
Ploppz
oh sorry I misread. I thought you were timing the compilation
-
lpg
it spins for 2.2 SECONDS just showing a progress bar before it runs my program
-
lpg
cargo build 2>/dev/null && ./target/debug/foo is significantly faster than cargo run which is stupid
-
talchas
lpg: yeah, this sounds worthy of a bug report
-
lpg
alright, on it
-
talchas
lpg: though I believe cargo run -q will solve this for now
-
talchas
in terms of "gets rid of the progress bar"
-
lpg
talchas: that's a great trick, thanks
-
WindowsBunny
lpg: conhost?
-
WindowsBunny
or linux terminal?
-
lpg
git bash on cmd.exe on conhost
-
WindowsBunny
k
-
WindowsBunny
lpg: so yeah, conhost writes are super slow, and cargo's progress bar has to iterate through *every* crate
-
lpg
yup
-
WindowsBunny
with a lot of progress bar updates for each crate
-
WindowsBunny
lpg: Definitely file an issue
-
lpg
that's the hunch that I had, filing an issue now
-
lpg
I learned that working on a TUI tool called magic-school-bus and had to do soooo many stupid buffering tricks to make it fast on Windows
-
WindowsBunny
mmm
-
WindowsBunny
lpg: conhost has some interesting performance characteristics
-
WindowsBunny
like, if you write out a whole bunch in a single syscall, every time the color changes takes some time
-
WindowsBunny
so filling the screen in a single color in a single call? super quick
-
WindowsBunny
filling the screen with different color per cell in a single call? kinda slow
-
lpg
it's also very easy to get tearing with conhost; the terminal doesn't wait for the application to refresh
-
lpg
unless there's a mode I can set for that, which would be nice
-
WindowsBunny
you have to ensure your writes are done in a single buffered up call
-
WindowsBunny
lpg: technically, you can have two console frame buffers, write to the hidden one, and swap it out
-
lpg
what if I'm already in alternate buffer mode via VT100 emulation?
-
WindowsBunny
then you have to create another alternate buffer and swap between them :D
-
lpg
I've been keeping around a virtual screenbuffer and diffing it every step to minimize the actual console writes
-
lpg
it's wasteful on most non-conhost terminal emulators since clearing+redrawing everything is fast enough usually
-
lpg
I filed this issue, which probably isn't perfect:
rust-lang/cargo #6661
-
lpg
golly, this affects cargo check too :(
-
wpage
lpg: could you do some kind of copy-on-write thing to capture changes as they're being made?
-
lpg
wpage: that might be kind of overkill since the total memory consumption to keep two terminal buffers around is very very small
-
lpg
the application I built using that has pretty distinct frames and is immediate mode-ish
-
wpage
diffing the whole frame is kind of expensive
-
wpage
depending on the size of the terminal window itself
-
lpg
can't be worst than what React does, right? :D
-
wpage
I don't know what react does - I've tried very hard to stay away from javascript development because of the framework-of-the-week situation there
-
lpg
React has been pretty stable for several years. You build a lightweight, ephemeral structure describing the shape of your UI and it's compared with the one from last time and used to incrementally update the DOM
-
wpage
lpg: but yea, I maximized my terminal window on a 2K display, and it's still only 8.27x as many cells as an 80x40 terminal, so diffing probably isn't that big a deal
-
lpg
I guess that is like 25 kB I have to diff for every screen update, which is not great
-
snek
is there a way to safely index into a vec
-
snek
i guess with a default would be ideal
-
snek
vec.nth(0).unwrap_or(default)
-
talchas
vec.get(0).unwrap_or_default() iirc
-
wpage
yep
-
wpage
the "get" method takes an index and returns an option
-
snek
ah get
-
talchas
though actually I think that you'd have to deref/copy, so it wouldn't actually work with just unwrap_or_default()
-
snek
didn't see that in the options
-
snek
guess i'm blind
-
lpg
if your type isn't copy, there's always Cow<'moo>!
-
snek
its a vec of gc wrappers
-
snek
so i have to clone anyway
-
Gankro
is it considered an anti-pattern for a crate to pub use a crate that is part of its public API, so users can just use their re-export instead of adding it to their cargo.toml?
-
naftulikay
I'm writing some automation around rustup. Is there a good command which will give me the platform tuple for the current host? (e.g. `x86_64-unknown-linux-gnu`) I can currently grep and regex the output of `rustup show`, but is there a better command for just dumping the tuple directly?
-
najamelan
I have a silly question. I have a struct with owned data. I want this struct to change type while just keeping the data, without extra memory allocation. How do I do that? Especially, if I do a.data = b.data; drop( b) will this copy?
-
prz
mem::swap
-
najamelan
ok cool thanks
-
jybs
Hey I posted this before - not sure if it made it to the channel as my network died. I'm looking for some info about the line where async becomes a good idea when using Tokio
-
talchas
async/await is certainly intended to replace futures/etc
-
mbrubeck
najamelan: For owned types, `a.data = b.data` will move the data out of `b`
-
talchas
(replace common use of future combinators, that is)
-
talchas
it's more about how much you're willing to run into rough edges and bugs
-
mbrubeck
for example if `data` is a String, this will not copy the contents of the string; it'll just make `a.data` point to the existing string data, and then mark `b.data` as uninitialized
-
talchas
starting with the fact that tokio is not built on 0.3 futures / async-await and you'll need to do compat stuff on all the boundaries
-
najamelan
mbrubeck Are you saying it's cheap to just assign
-
najamelan
and I shouldn't worry about it
-
najamelan
even if types are Copy?
-
mbrubeck
najamelan: Whether it's copy or move, the assignment will copy just the bits stored in that field, but won't do a "deep" copy of any data they point to
-
mbrubeck
najamelan: A very large copy type, like a [u8; 1024] array, may be expensive to assign
-
carllerche
talchas: tokio has an async/await preview feature flag
-
mbrubeck
najamelan: But a type like Vec or String or HashMap is just a few bytes
-
mbrubeck
and is cheap to move from one variable to another
-
j_ey
eval: std::mem::size_of::<String>()
-
eval
24
-
j_ey
I actually dont know what a hashmap is
-
j_ey
eval: std::mem::size_of::<HashMap>()
-
eval
error[E0465]: multiple rlib candidates for `debug_unreachable` found
-
eval
-
j_ey
(what the size of a HashMap I meant)
-
najamelan
ok, thanks I understand
-
najamelan
but with mem::swap that would be completely free?
-
najamelan
I mean is there a static way of changing the type around the data, without any runtime actions, just the compiler would now consider it a different type?
-
talchas
najamelan: mem::swap is just doing two assignments
-
najamelan
i two structs have exactly the same memory layout, and I want to say to the compiler consider this to be Y instead of X from now on.
-
talchas
technically, the compiler isn't required to make them the same memory layout in many cases where you think it would (though in reality it's not going to at the moment and may well never)
-
talchas
and the way would be transmute or something equivalent
-
j_ey
I would suggest constructing X
-
carllerche
najamelan you probably will want to annotate both as repr(C) or something
-
carllerche
najamelan: as mentioned, there is no guarantee that two structs w/ identical def have the same mem layout
-
najamelan
I need to have a fixed type because I deserialize, so the type needs to be known, but then I want to send it of to different actix actors which subscribe to certain types of messages with actix-broker. To be able to filter the messages, they need to be of the right type
-
najamelan
but actually they will all have the same fields with a vec<u8> payload
-
talchas
you could probably do this safely with just requiring a constructor, using a trait
-
najamelan
I know I can just construct, and it will copy pointers to the heap, but it just feels wrong to copy when there is actually no need, even though this is a micro optimization
-
najamelan
talchas, I don't exactly understand what you mean
-
talchas
I mean, fn foo(x: Foo) -> Bar { unsafe { transmute(x) } } and fn foo(x: Foo) -> Bar { Bar { stuff: x.stuff, other_stuff: x.other_stuff } } are identical
-
talchas
only the second one is guaranteed to work
-
j_ey
I would the safe and correct thing first
-
talchas
it's only if you wanted Box<Foo> -> Box<Bar> or other pointer types where you would actually be saving any performance skipping an allocation
-
talchas
remember that any foo = bar; or foo(bar()) or foo = bar(); or anything like that is a copy already
-
najamelan
yeah, I know
-
najamelan
when it's passed to or from function it's on a different stack frame after all. Not much we can do about that