-
nikki93
what are y'alls favorite talks on rust?
-
zadig
Hi guys, I've found something weird with lifetimes and things like f(expr). May be someone could answer me ? I explain:
-
zadig
buffer.resize(buffer.len() + foo, 0); doesn't compile, with buffer a mutable ref
-
talchas
zadig: the issue is that that's Vec::resize(&mut buffer, buffer.len() + foo, 0)
-
talchas
there is hope to fix this Soon(ish)
-
zadig
talchas, that's not normal, isn't it ?
-
nox
zadig: That requires non-lexical lifetimes, which are not stable yet, check whether that compiles in nightly with #![feature(nll)] in the crate root.
-
zadig
nox, alright
-
emerentius_
in the meantime, use a temporary
-
zadig
thanks for your anwser :)
-
zadig
yup
-
nox
zadig: I know this is covered in the NLL RFC, but I am not sure the unstable feature already implements that part of it.
-
nox
(yet)
-
zadig
okay :)
-
zadig
not a big issue, but just not logical at the first view
-
nox
zadig: For sure.
-
neachdainn
How does one re-export macros?
-
durka42
there is no way to do so on stable
-
neachdainn
So structopt's README is lying?
-
durka42
it requires #![feature(macro_reexport)] (old, soon deprecated way) or #![feature(use_extern_macros)] (new way)
-
» durka42 checks
-
durka42
I don't see anything about re-exporting macros in the readme?
-
neachdainn
No, but you also don't see a single `extern crate structopt_derive;` either
-
durka42
-
durka42
I vaguely remember seeing a debate about whether it's a bug that this works without #![feature(use_extern_macros)] :)
-
neachdainn
Maybe it's slightly different because it's a proc macro?
-
neachdainn
Just wildly guessing
-
lgspaw
is there a Some(v) | None for hashmap?
-
lgspaw
i see Entry, but no nice way to convert Entry => Option
-
durka42
lgspaw: are you looking for HashMap::get?
-
lgspaw
hm
-
lgspaw
this is different from `[]`?
-
durka42
neachdainn: yeah but proc macro scoping is supposedly unstable :p
-
durka42
lgspaw: right, indexing simply panics if the key doesn't exist
-
lgspaw
ohhhh ok ;)
-
lgspaw
thank you, this is exactly what im after
-
gchristensen
is there an Either type for results which aren't a Result?
-
lgspaw
need to get better at reading these doco, i shoulda just searched for "-> Option" on that page
-
durka42
!crate either
-
rustbot
either (1.4.0) - The enum [`Either`] with variants `Left` and `Right` is a general purpose sum type with two cases. ->
crates.io/crates/either <
docs.rs/either>
-
gchristensen
oh. right. I should really search crates first :( thanks!
-
neachdainn
`either` seems like one of those crates that should be in the standard library
-
gchristensen
it isn't quite as nice as I expected. Result is great because Err, Ok are semantically sensible whereas I don't care if it is Right or Left
-
jybs
For setting guid and uid on linux is an unsafe box with libc calls my best bet?
-
jybs
-
durka42
-
lgspaw
is there a function on Option that does (Some(2)).f(|x| Some(x+2)) to return Some(4)
-
lgspaw
(not map)
-
durka42
lgspaw: and_then'
-
lgspaw
ahhh
-
lgspaw
perfect
-
lgspaw
was looking for bind
-
talchas
yeah, bind is generally spelled and_then in rust
-
durka42
oh no, a haskeller :p
-
lgspaw
ok, good to know
-
talchas
(same with result and futures)
-
lgspaw
nope, coming from F# :)
-
durka42
soon you'll be asking how to do GeneralizeNewtypeDeriving and HKT
-
talchas
durka42: haskell spells bind >>= :P
-
talchas
(but yeah yeah, a haskeller would probably look for bind)
-
lgspaw
in F# its Option.bind for option coz no trait system
-
sarnold
hrm nix lacks fchown, lchown, fchownat :(
-
cjm
can you specify rustc flags in cargo.toml? specifically "target-cpu=native"
-
lgspaw
usually you end up doing let (>>=) o f = Option.bind f o in the domain though
-
talchas
lgspaw: well, it's not a trait here either, just the whole inherent impl thing
-
lgspaw
hmm ok, so in this case its just a method?
-
talchas
(because you can't define Monad well without HKT, and the workarounds are ugly and probably have issues)
-
talchas
yeah
-
durka42
cjm: you can specify them in .cargo/config
-
lgspaw
fair enough
-
durka42
which is the second, secret, Cargo.tonml
-
sarnold
-
talchas
trait Monad { fn and_then<B>(self) -> Self<B>; } does not work
-
lgspaw
why is there no HKT if there is traits? it seems like it should be possible to encode them
-
talchas
er, well, missing the function, but whatever
-
talchas
that's the part that doesn't work
-
talchas
lgspaw: you can, that's the ugly workaround
-
lgspaw
right
-
talchas
-
cjm
durka42: the filename is just "config"?
-
talchas
"fn seq<F>(&self, fs: <Self as HKT<F>>::T) -> <Self as HKT<U>>::T where F: Fn(&<Self as HKT<F>>::C) -> U {" look at that type line
-
durka42
in a dir called .cargo, yes
-
cjm
ok, thanks
-
durka42
talchas: no I refuse :)
-
durka42
I think it says "fnord"?
-
lgspaw
interesting :) it isnt pretty but it works
-
talchas
and then I don't want to think about what a free function that's generic over M: Monad is supposed to look like
-
lgspaw
those type constraints on the impl are complicated (line 170)
-
lgspaw
i dont think im quite at that level in rust to grok that well
-
talchas
(you can't write the type equalities you might need at times, you can't write for<T> <M as HKT<T>>::U: Monad, etc)
-
darkwater
hey, could anyone tell me how to get an X window using gtk-rs/cairo?
-
darkwater
or in other words, using cairo with xcb backend
-
darkwater
wait can i just use the xcb crate to get a connection?
-
centril
talchas: well no... not generally... (>>=) is flat_map for iterators
-
centril
mbrubeck: glad you like it =)
-
jybs
Is there a way to locate unused Cargo.toml entries easily?
-
ishitatsuyuki
jybs: you mean deps?
-
jybs
Yup
-
ishitatsuyuki
Put #[warn(unused_extern_crates)] at the main.rs/lib.rs, run compiler
-
talchas
centril: it's flat_map for Iterator and and_then for Option Result Future Stream (sorta)
-
jybs
Sweet!
-
ishitatsuyuki
And you need to match the extern crate statements in the source file and Cargo.toml to see if there's an obsolete
-
centril
talchas: bit unfortunate that it isn't called `bind` or something more consistent
-
talchas
(I guess the best description of Stream is a stack, so that and_then is bind or lift bind)
-
centril
talchas: lift bind?
-
centril
are you referring to :: Applicative f => f (a -> b) -> (f a -> f b) ?
-
Saethlin
Is there any reason I shouldn't just wrap my entire program in a tokio::executor::current_thread::run(|_| { ?
-
ishitatsuyuki
Sudden haskal
-
centril
Haskell*
-
talchas
centril: well, I forget what it would actually be
-
talchas
to apply bind to the correct place in a monad transformer stack
-
centril
talchas: oh, lift :: (MonadTrans t, Monad m) => m a -> t m a
-
ngc0202
hmm so I set RUST_BACKTRACE=1 and my entire backtrace is: mingw_set_invalid_parameter_handler
-
talchas
yeah
-
ngc0202
what is that supposed to mean
-
talchas
and lift (>>=) isn't actually a thing, but "something vaguely like that"
-
centril
-
talchas
oh, I wasn't thinking of any particular actual function
-
talchas
besides that lift is vaguely the correct terminology
-
centril
talchas: some day we might be able to encode such things and indexed monads in Rust =P
-
sleffy
Challenge: what's the simplest way to write `fn flatten(Option<Option<T>>) -> Option<T>` in Rust?
-
sleffy
`opt.and_then(|x| x)` is simple but I want to know if there's a simpler way
-
centril
sleffy: fn flatten(opt: Option<Option<T>>) -> Option<T> { opt? }
-
sleffy
centril, does that really work? I was under the impression that `?` must happen within a function returning `Result` at the moment?
-
centril
sleffy: na, it works for Option now
-
sarnold
I thoguht nightly relaxed that?
-
centril
works on stable.
-
sarnold
wow
-
sleffy
holy crap!
-
sleffy
AWESOME
-
sleffy
:D :D :D
-
sleffy
centril, that's still within a function block though
-
» centril doesn't think it rises to the level of holy crap =P
-
sleffy
Is there a proposal for `Option::joint`?
-
centril
sleffy: join* ?
-
sleffy
centril, well rain on my parade, fine. I just like to get excited about everything I can :D
-
sleffy
centril, join, yes
-
sleffy
flatten
-
sleffy
It's monadic join, after all `(>>= \x -> x)`
-
centril
sleffy: you could propose it =P
-
sleffy
too busy right now
-
lachlansneff
Will the compiler optimize away slices created with slice::from_raw_parts if I just use it for "random" memory accesses?
-
lachlansneff
I'm having some weird intermittent errors
-
lachlansneff
That could indicate that
-
sleffy
lachlansneff, I assume it might but only if it can optimize away the bounds checks.
-
sleffy
What's going on?
-
centril
lachlansneff: try it out with
godbolt.org =)
-
sarnold
normally optimizations aren't visible unless you're doing something that trips undefined behaviour
-
sleffy
^^
-
sarnold
or godbolt, of course :)
-
ngc0202
so I set RUST_BACKTRACE=1 and my entire backtrace is: mingw_set_invalid_parameter_handler
-
ngc0202
what is that supposed to mean
-
sarnold
ngc0202: still no luck? :(
-
ngc0202
lol :)
-
ngc0202
not at all
-
sarnold
ngc0202: can you swap to the native windows toolchain andsee if it gives a more sensible result?
-
ngc0202
yeah I guess I could try that
-
ngc0202
that's gnu or what?
-
sarnold
MS Visual somethingosmething..
-
ngc0202
oh wait
-
ngc0202
that's what I thought I was using, but I only have it for stable not nightly
-
ngc0202
that explains some things
-
lachlansneff
sleffy: I'm writing the vga buffer driver for a small "os"
-
lachlansneff
Basically, it writes data to 0x8000
-
lachlansneff
And that gets displayed on the screen
-
lachlansneff
Sometimes, seemingly randomly, it doesn't display
-
Mutabah
lachlansneff: What architecture?
-
lachlansneff
x86_64
-
Mutabah
lachlansneff: Also, you might want to use voltaile_write instead of a slice, otherwise the compiler is free to optimise out the write if it determines that it's never read
-
Mutabah
lachlansneff: ... why is the display at 0x8000 on x86_64?
-
lachlansneff
mutabah: Will do
-
lachlansneff
And whoops, I meant 0xb800
-
lachlansneff
*0xb8000
-
Mutabah
if you're using qemu, and stopping your simulation with `cli; hlt` - watch out, last time I checked that will freeze the display without refreshing it (i.e. video writes just before the halt won't be reflected)
-
jpernst
does anyone here by chance use both rental and owning_ref?
-
sleffy
jpernst, I use owning_ref. Not rental though.
-
jpernst
i'm considering increasing the scope of rental for the next version to include use cases covered by owning_ref, and am wondering if people would find that useful
-
jpernst
possibly also with a macro that easily generates sound analogs of OwningHandle for any type
-
jpernst
since it seems the OwningHandle scenario is fairly popular
-
lachlansneff
mutabah: Now seems not to be working at all
-
lachlansneff
Does this look right to you?
-
lachlansneff
-
Mutabah
lachlansneff: what type is VGA_BUFFER?
-
lachlansneff
mutabah: It's *mut 16
-
lachlansneff
Whoops, sorry, `*mut u16`
-
Mutabah
Looks sane to me... assuming taht VGA_BUFFER is correctly set to b8000 and you're running in VGA text mode
-
lachlansneff
Hmm
-
lachlansneff
Seems to work when I comment some unrelated stuff out
-
sleffy
If I'm about to start building a large and complex CLI with clap, what should I be using? The Rust representation, the YAML representation, or the macro representation?
-
lgspaw
can you add a method (impl) to a type outside its crate?
-
lgspaw
(e.g. type Test<'a> = HashMap<u32,something<'a>>; impl<'a> Test<'a> { ... }
-
lgspaw
)
-
sleffy
lgspaw, I believe not.
-
sarnold
lgspaw: I think "sortof". You can via new traits ..
xion.io/post/code/rust-extension-traits.html
-
sleffy
Yes, extension traits are one idiom to do this
-
sleffy
Another is a newtype (`struct Test<'a>(HashMap<u32, something<'a>>);`)
-
lgspaw
is the other option to create a container type with a struct, then impl the struct?
-
sleffy
And then implementing your methods on it
-
lgspaw
ahhh
-
sleffy
And then implementing `Deref/DerefMut` on that struct to hackily get your methods back :)
-
lgspaw
yeah thats what i was thinking, didnt know you could make an anonymous struct like that though :)
-
sleffy
lgspaw, yeah, they're called tuple structs! You can make 'em with as many tuple fields as you like
-
lgspaw
cool
-
lgspaw
how do you access the member?
-
lgspaw
ah i see there is a doc on tuple struct :)
-
lgspaw
ahh, you destructure it
-
durka42
or .0, .1 same as normal tuples
-
lgspaw
neat, i havent even come across tuples yet
-
tremolo
Hi. Say I want to compile some Rust and compile some C and link them together.
-
tremolo
With cyclical dependencies
-
tremolo
Is it possible to do it with Cargo?
-
tremolo
Or do I need to do the linking myself?
-
sleffy
tremolo, you may want to use a build script
-
Lymia
Is there a good idiom for doing a "struct object" similar to trait objects?
-
sleffy
Lymia, what would a struct object be?
-
Lymia
I have a non-object safe trait, which I can wrap a struct around -- the inherent methods of which would be object safe.
-
ngc0202
how do I just parse my own keyword in syn?
-
sleffy
Lymia, ooh, interesting
-
sleffy
I hit a very similar problem recently but did not find a solution. Would be curious to know if anyone else here knows
-
Lymia
The best approach I can think of is to make a trait, then impl <T> Trait for WrapperType<T>
-
Lymia
Possibly wrap it in a struct, with, like, struct Wrapper(...); impl Wrapper { fn new<T:NonObjectSafeTrait>(t: T): Wrapper }
-
sleffy
Lymia, aye, but you've got to figure out how to erase the type inside `Wrapper` somehow
-
Lymia
Where the contents of the Wrapper is a Box<WrapperInternalTrait>, which is trait WrapperInternalTrait { ... } struct WrapperInternal<T:WrappedTrait>(...); impl <T:WrappedTrait> WrapperInternalTrait for WrappedTrait<T>?
-
Lymia
But that's not very DRY
-
Lymia
Lots of shim methods :c
-
Lymia
I guess a natural extension to the proposed "dyn Trait" syntax is
-
Lymia
Something like "dyn SomeStruct<_>"
-
Lymia
Though figuring out the semantics of that is hard
-
docbrown
ngc0202: This syn example shows how to parse a custom syntax:
github.com/dtolnay/syn/tree/master/examples/lazy-static
-
ngc0202
hmm could you point me to a line?
-
docbrown
-
ngc0202
oh
-
ngc0202
well that's a custom parser from existing syntax
-
dtolnay
ngc0202: parsing a custom keyword would be similar to that link
-
dtolnay
the two parsers you would want are:
-
dtolnay
`ngc0202: syn!(Ident)`
-
dtolnay
followed by
-
dtolnay
`cond_reduce!(ngc0202 == "ngc0202")`
-
ngc0202
ahhh didn't think of that
-
ngc0202
thanks! great library btw
-
ngc0202
shoutout to geal too
-
ngc0202
woah, I just found parse_quote omg that cleans up some codeblocks so much
-
lpg
Rust code now part of supporting tooling at my job! :D
-
Saethlin
lpg: Oo that's cool! Can you tell us anything about it?
-
dbkaplun
up to 4 lines of JS. :|
-
dbkaplun
-
lpg
It was a little bit of greenfield tool development I did in my spare time, and it ended up being useful
-
lpg
Adopted because it was useful, and it just happened to be in Rust!
-
Saethlin
Nice!
-
lpg
It's also open source I guess!
-
Ralith
hurray!
-
Ralith
I need to make that happen at my workplace
-
Ralith
so far I'm mostly just doing it with nix
-
ngc0202
I pitched rust at my job interview lol
-
ngc0202
and I got the job
-
ngc0202
so maybe someday I'll have rust at work :)
-
ngc0202
gotta graduate first
-
Cetra
we're using a 30k LOC app in production
-
ngc0202
30k LOC rust?
-
ngc0202
i'm jealou
-
ngc0202
s
-
lpg
this project is only 1.5k LOC right now, lol
-
ngc0202
I'm at 1.1k loc for the gubment
-
ngc0202
but i think it's technically just a prototype and they're not going to use it
-
lpg
(well, 1.5k Rust, 1.6k Lua right now I guess)
-
lgspaw
i keep hitting brick walls when passing around hashsets to different functions, is there a more idiomatic way of doing this
-
lgspaw
(perhaps i should be looking to use impl instead of plain functions)
-
lgspaw
s/hashsets/hashmap
-
stephaneyfx
lgspaw: May you give an example of wall you've hit?
-
lgspaw
sure, i dont have really clear examples, but i was passing around HashMap (using insert in different functions) and i kept getting lifetime errors
-
lgspaw
it started to get unweidly and it seems mostly due to my lack of understandings of lifetimes
-
lgspaw
when i put everything in an impl, it seems most of those errors go away
-
stephaneyfx
lgspaw: If you could come up with an example of the playground, that would help. I am not sure what errors you got.
-
stephaneyfx
*on the playground
-
lgspaw
let me see if i can try
-
stephaneyfx
lgspaw: What is the type of your hashmap?
-
lgspaw
its a bit of a complex type, let me paste it
-
lgspaw
-
lgspaw
the main problem became passing the Cache around, i kept basically guessing what lifetime specifier, what mutability etc
-
stephaneyfx
Did you pass it as `&'b mut Cache<'a>`?
-
lgspaw
yeah
-
lgspaw
oh
-
lgspaw
no
-
lgspaw
i did &'a mut Cache<'a>
-
lgspaw
:(
-
stephaneyfx
This would cause the borrow of the cache to last too long
-
stephaneyfx
Because &'a mut T is invariant in T
-
lgspaw
im very unclear on this syntax, i should probably give this section of the book a read
-
stephaneyfx
-
lgspaw
excellent, i will read this
-
thugthggy
Hi what can one do with rust why is this new language
-
WindowsBunnyHasALongSuffixToday
thugthggy: You can write software in Rust
-
Mutabah
Hello thugthggy, Rust is a general-purpose system-level language - You can write almost anything in it
-
Saethlin
almost?
-
thugthggy
write like what ?
-
thugthggy
games?
-
Saethlin
CLI apps, GUI apps, web servers, operating systems, games, compilers,
-
thugthggy
Video-games? Web apps ?
-
WindowsBunnyHasALongSuffixToday
A web browser, a game, a terminal, an IRC client, whatever
-
WindowsBunnyHasALongSuffixToday
web apps is tricky
-
WindowsBunnyHasALongSuffixToday
In particular on the client side
-
Cetra
well tbh with wasm
-
thugthggy
what is the difference between webapp and webserver ?
-
Cetra
semantics
-
WindowsBunnyHasALongSuffixToday
You can use wasm to do number crunching on the client side, but you still need JS to actually do any sort of IO with the user
-
Cetra
-
thugthggy
wasm ??
-
WindowsBunnyHasALongSuffixToday
on the server side you can of course use Rust all you want
-
WindowsBunnyHasALongSuffixToday
but Rust in a browser is limited to what webassembly is able to do
-
thugthggy
any languge need JS on webbrowser correct ?
-
WindowsBunnyHasALongSuffixToday
Webassembly depends on there being JS to call into the webassembly and do something with the results
-
WindowsBunnyHasALongSuffixToday
and any language that compiles to webassembly therefore needs JS still
-
thugthggy
where there is no language alternative to js ?
-
WindowsBunnyHasALongSuffixToday
There is no true alternative to JS at the moment
-
WindowsBunnyHasALongSuffixToday
there are some languages that transpile to JS like coffeescript and so on
-
Yaniel
so, not too different from android and java a few years back
-
thugthggy
sad
-
thugthggy
javascript is the hardest language to me
-
Cetra
typescript makes it better
-
thugthggy
what is typescript
-
Cetra
it's javascript with types
-
Cetra
transpiles down to javascript
-
thugthggy
i like type systems
-
thugthggy
Int :: Int -> Int like this ?? js with types means?
-
lgspaw
ok damn you rustfmt, can i stop rustfmt from putting newlines in struct instantiation? its turning a 500 line program to 900
-
lgspaw
been over configuration.md twice and i cant seem to find it
-
scottmcm
WindowsBunnyHasALongSuffixToday: queued, interesting. Thanks for sharing!
-
CognitiveRadiation
what's the most straightforward way to match on an Rc<String>?
-
centril
CognitiveRadiation: deref to a &str and match on that?
-
centril
CognitiveRadiation: you might also be interested to know that you can use Rc<str> instead with less indirection and overhead
-
remexre
Is there a parser crate that lets me get completions easily? I'm trying to implement a REPL; I can get everything that can be completed for a given CST node fairly easily, but actually going from index in the text to a CST node is hard
-
» centril knows remexre secretly wants optparse-applicative
-
remexre
ha, this isn't for CLI options though -- I discovered structopt recently and I'm liking it just as much, since then I can reuse the doc-comments on my Options type as --help info
-
centril
remexre: oh that is fancy
-
centril
remexre: btw how goes the frunk stuff?
-
remexre
ahhhh
-
remexre
I'll do that _right_now_
-
centril
remexre: awesome
-
centril
remexre: btw... I moved Coprod into frunk_core
-
centril
so the traits should be in frunk_core as well I think
-
remexre
ok
-
lgspaw
why does or_insert_with return a mutable reference, as opposed to just a reference?
-
lgspaw
(in hash_map, sorry)
-
lgspaw
(infact all the methods do)
-
Mutabah
Well, if you're inserting, a mutable refeence is the useful thing to return
-
Mutabah
Taking &mut and returning & is kinda useless
-
remexre
wrt why all the methods do, it's partially a hack around not having NLLs too
-
lgspaw
hmm thats true, i suppose entry() returns a &mut
-
scottmcm
lgspaw: it's to let things do `.or_insert(0) += 1` work
-
lgspaw
it wouldnt have occured to me to use such a thing
-
remexre
centril: For the name, AUnion (A = anonymous), ExtensibleCoProduct / ExtCoProduct, CoHList, or something else?
-
lgspaw
so, when you use .or_insert on the rhs of a match case, how do you balance this type if the contents of the HashMap are Option?
-
lgspaw
do you need to use &mut None?
-
lgspaw
or do you usually deref the result of or_insert
-
jon
I have a function foo() -> Box<Future<Item=Bar, Error=Box<Error>>>. When I return a Box::new(ok(instance_of_andthen)) the compiler message seems incorrect to me: expected struct 'futures:AndThen', found struct 'Tile'. Shouldn't that be the other way around?
-
lgspaw
oh derefing seems to work well, hmm
-
jon
Replace Tile with Bar :)
-
lpg
lgspaw: there's a nightly feature that improves the ergonomics of reference matching that'll make that a little better too
-
remexre
jon: What's ok() doing there? Why not just Box::new(and_then_thingy)
-
lgspaw
interesting
-
jon
remexre: it's there because I'm still wrapping my head around futures :)
-
remexre
ha, fair
-
pingzing
Is there a way to pass environment variables directly to cargo on invocation? For example, I'm cross-compiling, so openssl needs PKG_CONFIG_ALLOW_CROSS=1 set.
-
remexre
jon: So ok(T) -> Future<T, _>, so if you do ok(Future<T, E>), you get Future<Future<T, E>, E2>
-
jon
So ok is used to turn something that's not a future into a future?
-
remexre
yup
-
remexre
The error message is backwards though, I _think_ that might be because it's doing unify(TraitObjectType, ReturnType) instead of unify(ReturnType, TailExprType), but I haven't actually done anything with rustc, so idk for sure
-
jon
I found an issue about it, not sure if it's been fixed.
rust-lang-nursery/futures-rs #402
-
CognitiveRadiation
I have a module with a number of enums that I use variants of frequently
-
CognitiveRadiation
so I have use self::Enum::*; at the top of all my functions here
-
CognitiveRadiation
is there a way I can make the scope of the `use` be greater than a single function, so I don't have to type all of htem?
-
jon
Can tokio (not tokio_core) be used with hyper?
-
albel727
so, could you not just lift use statement outside the functions?
-
lgspaw
-
albel727
lexical lifetimes. self is considered borrowed by get_a() until the end of the expression, that is the semicolon after get_b() call.
-
albel727
the NLL feature should solve that.
-
lgspaw
ahh
-
albel727
but meanwhile what you did in test2() is the sane workaround.
-
lgspaw
when is NLL coming?
-
albel727
no idea, tbh
-
lgspaw
fair enough
-
albel727
it is already there in nightly, but when it's gonna be stabilized
-
albel727
only the rust devs know
-
lgspaw
oh, im using nightlies, perhaps there is some feature i need to enable
-
scottmcm
#![feature(nll)]
-
lgspaw
awesome
-
rnd-M
Interestingly the error message actually implies that that self is already borrowed immutable by the outer method call before the compiler actually tries to calculate the function parameter. And not the other way around.
-
lgspaw
hoo boy feature(nll) gave me some interesting results :)
-
jeikobu
-
lgspaw
awesome
-
albel727
> the error message actually implies that that self is already borrowed immutable by the outer method call <-- yeah, this might be closer to the truth. I'm not sure of the actual order of borrows inside expression, just that in this case there are two borrows in one.
-
albel727
s/closer to the truth/closer to compiler reasoning/
-
albel727
(the truth is of course in computing the inner expression first :>)
-
rnd-M
Can someone give me a hint why this [1] compiles on the playground without the "rc" feature flag [2] for serde?
-
rnd-M
-
rnd-M
-
albel727
1) I'm not exactly sure that the list of crates comes verbatim from integer32llc 2) some of the listed packages in there may require serde and enable feature "rc" themselves
-
albel727
as crates are compiled with the union of all features from all dependencies
-
albel727
and not just with features that are specified in your cargo.toml directly
-
rnd-M
Thanks! Didn't had in mind that all features are joined before the the crate is actually compiled.
-
tomtom
how can i serialize a boxed trait ? it doesn't seem possible for serde
-
rnd-M
Did you include the `alloc` feature? (
serde.rs/feature-flags.html)
-
pingzing
can anyone speculate why a create with a native dependency may compile in one project, but fail in another? seems to be a linking issue
-
tomtom
rnd-M: no I haven't seen that how can I try it?
-
albel727
boxed trait is a trait object. it doesn't seem possible for anything to serialize it. unless of course you add a serialize_to_json() method or somesuch in your trait.
-
albel727
which would internally call serde_json::serialize() or somesuch
-
rnd-M
tomtom: I assume you can't test the feature in the playground. Locally you just need to edit your Cargo.toml to sth. like: `serde = {version = "1.0.27", features = ["alloc"]}`. But as albel727 mentioned it may doesn't work at all but I would still give it a try.
-
tomtom
rnd-M: i get #1[feature] may not be used on the stable release channel then
-
albel727
-
rnd-M
tomtom: Based on their documentation it seems like the `alloc` feature is nightly only. You need to run it with the nightly toolchain.
-
albel727
it certainly won't work because but trait objects, inside of Box or not, are unsized blobs of unknown and there's no safe way to get to their contents or figure out how to serialize them, unless you have a method to serialize them passed through their virtual table.
-
albel727
s/but//
-
centril
-
albel727
now how could I even live without cats in labels.
-
centril
albel727: =P
-
tomtom
albel727: thanks, your solution seems to compile well :)
-
glandium
is there a way to test whether some item can be "imported"? I'd like to use SYS_mmap2 from the libc crate when it exists... except it only exists on a few platforms. Do I have to manually do cfg() juggling?
-
» albel727 only knows the cfg juggling way, and highly doubts there is or will be another one
-
glandium
:(
-
glandium
that's where #ifdef is actually useful
-
albel727
yeah. well, you can always add a feature to your crate that would enable or disable use of sys_mmap2(), and so shove the responsibility onto your library users :>
-
albel727
presumably they will be able to test for current arch and enable the feature accordingly
-
albel727
you may invent your poor man contraption in build.rs that would behave like configure and enable features accordingly :>
-
glandium
albel727: haha a compilation test with use libc::SYS_mmap2?
-
albel727
yep :>
-
glandium
that's almost not a bad idea
-
albel727
but don't tell anyone I gave you ideas, or I'll be burned at stake
-
albel727
(and it's ugly still ._.)
-
glandium
I'll burn your name in the build.rs
-
albel727
nooooooooo
-
albel727
well, there are too many subtle things to consider. you'll have to properly pass things for cross-compilation, etc.
-
albel727
I wouldn't be brave enough to attempt this normally, unless I have absolutely no choice.
-
albel727
maybe I'd just use cc crate to compile a small C program with the #ifdef or call attempt, so that cc crate handles all this for me. ...and then hope that libc actually has the definition too. ._.
-
Xion_
The compilation is not really a bad idea, I believe this is what ./configure scripts of yore did sometimes
-
albel727
>you may invent your poor man contraption in build.rs that would behave like *configure* :>
-
Xion_
Ah :)
-
albel727
iow, exactly >_>
-
Xion_
Build scripts are fun sometimes.
-
Xion_
Reminds me that I should make a small helper crate for unhygienic code generation from build scripts :)
-
albel727
for sometimes ~ equal to 0.01% of the time :>
-
albel727
all the other time they're the horror <_<
-
Xion_
(mostly so it keeps indentation levels correct)
-
Xion_
Well so far my most elaborate build contraption is this:
github.com/Xion/ezomyte/blob/master/build.rs
-
Xion_
Featuring generatio of enums and Deserialize impls from a JSON spec
-
albel727
hmm, indentation levels... sounds like a work for rustfmt :>
-
Xion_
Autoformatters are the devil so I don't use them :P
-
albel727
but but
-
Xion_
no buts
-
albel727
but I need mine still :>
-
nox
Not even generating Rust code through Python, so casul
-
albel727
well, as a first approximation, I wouldn't do compilation tests. I'd just check target arch in build.rs and enable feature when I deem it safe.
-
Xion_
I have at least one project where I use Python to automatically copy the usage output from clap into README
-
Xion_
Does that count? :)
-
albel727
hmm
-
glandium
nox: I'm going to generate rust code from C++, but I'm still pondering whether to do that in python or rust
-
nox
glandium: IPDL stuff?
-
albel727
that sounds almost like markdown should be another "completion script" target or something.
-
glandium
nox: no, pure C++
-
albel727
for clap.
-
nox
glandium: I mean, what's that Rust code you generate?
-
Xion_
-
glandium
nox: something awful, you don't want to know :)
-
Xion_
I especially like the arbitrary cutting out empty lines
-
Xion_
(and not empty ones, too)
-
nox
glandium: I see you know me well.
-
SuperFluffy
What's the RFC for removing the generic types so you don't have to specifiy impl<T> Foo for Bar<T>?
-
SuperFluffy
This was covered in the impl period, right? Hope I am not mistaking something.
-
Xion_
wat
-
Xion_
That's moronic. Is it actually real? o_0
-
SuperFluffy
Xion_: Given your reaction, probably not. O.O
-
Xion_
I mean, after it was deemed that `ref` is too much of a complication, I wouldn't be *too* surprised
-
Xion_
Implicit > explicit seems to be Rust motto as of late
-
Mutabah
I remember one that propagated bounds from the type to the impl block
-
nox
It's not done yet AFAIK.
-
Xion_
That one I wouldn't mind, since I like having thematic impl blocks
-
nox
aturon or woboats can confirm.
-
Xion_
Though I'd prefer if it was something like `impl<_> Foo` rather than `impl Foo`.
-
SuperFluffy
So was there something along these lines or not?
-
SuperFluffy
I probably misremembered
-
centril
Xion_: id :: a -> a ; id = \x -> x it is entirely reasonable to elide the forall. part
-
nox
SuperFluffy, Xion_: IIRC the PR landed, but isn't implemented, and it's not sure it will become stable anyway.
-
woboats
Xion_: the way you're communicating makes me bummed out, fyi
-
woboats
but there's no RFC for `impl Foo === impl<T> Foo<T>` or something
-
Xion_
centril: Which would be the equivalent of impl<> Foo for Bar<>
-
Xion_
Not impl Foo for Bar which is ambiguous
-
nox
woboats: They mean impl Foo<T> I think.
-
SuperFluffy
^
-
woboats
I think people are referring to "implied bounds" - if you have `struct Foo<T:Bar>` `impl<T> Foo<T>` works
-
woboats
nox: that's also not a thing
-
centril
Xion_: you can certainly elide <> to nothing
-
SuperFluffy
woboats: nox indeed understood me right.
-
Xion_
centril: And then it's not clear if the trait itself is parametrized
-
SuperFluffy
woboats: I was thinking of impl<T> Foo<T> = impl Foo<T>
-
centril
Xion_: you are arguing readability, I'm arguing what is technically possible
-
woboats
SuperFluffy: the concern with that has to do with shadowing
-
nox
Ah it never made it to the RFC I see.
-
» SuperFluffy chuckles about Foo<T> == foot ...
-
Xion_
centril: Not everything that's technically possible should be done :)
-
centril
SuperFluffy: that is not doable... T can be a concrete type
-
woboats
what if you have a glob import that adds a type called `T`
-
woboats
now its no longer a generic type
-
Xion_
centril: something something preoccupied scientists ;)
-
nox
SuperFluffy: Some Erlang people name their state record 'ate',
-
woboats
unlikely for `T` of course, but if you did something like `impl Foo<Ptr>`
-
SuperFluffy
woboats: Yeah, indeed. I was just thinking about that.
-
nox
so they can name the variable St and do St#ate.
-
SuperFluffy
Well, let's ban single-character types and reserver A, B, ..., T for generics? :D
-
nox
SuperFluffy: Or just don't omit them and make the next person who will read the code happy.
-
Xion_
^
-
centril
woboats: tho if we roll back history and say that initial caps-idents are for concrete types and initiaö-lowercase is for type variables then it works fine like in Haskell, but we can't roll back time
-
centril
s/initiaö/initial
-
Xion_
nox: Reminds me of the attr library in Python
-
Xion_
(which has API like attr.s and attr.ib)
-
Xion_
(quite del.icio.us, I'd say)
-
» centril is very fond of Haskell syntactically
-
SuperFluffy
centril: Have you worked with idris?
-
nox
Xion_: I'm ok with implied `ref`, I'm not ok with implied `mut`.
-
nox
Xion_: Implied `ref` at worst can cause a compile error because you tried to consume the binding later but it was actually a reference,
-
centril
SuperFluffy: No; I've only read about Idris - I've used Haskell extensively and Agda a bit tho
-
nox
implied `mut` means I can mutate the damn value in the middle of nowhere without any sort of visual cue.
-
centril
I like what I've seen so far
-
glandium
pastebin.mozilla.org/9078384 such consistency across libcs... when what supports those syscalls is the kernel
-
Xion_
Tbf, the fact that Rust requires `mut` for local variable mutation can be seen as weird in itself
-
SuperFluffy
centril: After reading tdd with idris, I was confused that I couldn't return types in rust. :D
-
albel727
>`mut` for local variable mutation can be seen as weird in itself <-- let it be seen as such, idgaf
-
Xion_
And who knows, maybe the lack of `ref` will bring some consistency as to what and when is deref, or de-derefed, automatically
-
nox
glandium: There is a crate for mmap.
-
Xion_
albel727: Blasphemous infidels, those who think that, yes ;p
-
albel727
:D
-
nox
Xion_: I disagree about it being weird.
-
centril
SuperFluffy: you can - use associated types as type families
-
glandium
nox: it uses libc
-
nox
Xion_: If I init a value immutably, I want it to be the same 30 lines later, barring internal mutability.
-
albel727
immutable by default vars. best thing for reasoning since coffee
-
nox
glandium: Oh, that's your custom allocator?
-
nox
albel727: People want `mut` to be implied on owned values.
-
albel727
let them use another language then
-
Xion_
And have cake.
-
glandium
nox: yes, and I do need to use syscall() because of stupid LD_PRELOADs wrapping mmap
-
albel727
>but but muh implicit things saves on typing <-- should direct efforts towards a sane ide then.
-
nox
albel727: Some people argued that your IDE can tell you a variable is actually mutated.
-
woboats
When Niko has expressed that `mut` on owned values might be silly boilerplate, maybe you shouldn't be so sarcastic about that opinion
-
glandium
nox: an IDE shouldn't be mandatory to review code
-
albel727
^
-
nox
woboats: Could you not call that property that I value 'silly'? Thank you very much.
-
nox
glandium: I 100% agree.
-
centril
Personally, I like the 'mut' keyword; feels like a good hint where it matters
-
nox
Just because I own a value doesn't mean I should be able to mutate it.
-
albel727
^
-
glandium
is there a way to tell cargo to use something else than link.exe when linking for an msvc target
-
glandium
?
-
centril
But let's respect disagreements shall we and discuss only based on merits?
-
nox
centril: Sure.
-
woboats
i think the important point is that `&/&mut` is a much more meaningful distinction than mut or not on a local variable
-
woboats
from the point of view of correctness of the rest of your program, you *can* mutate anything oyu own
-
nox
No.
-
nox
From the POV of safety, sure.
-
nox
Not correctness.
-
nox
Correctness implies the absence of logic errors.
-
nox
Mutating something that I don't expect to mutate is a logic error.
-
woboats
this is why i said correctness of the rest of your program
-
nox
I don't see why "the rest" changes something here.
-
nox
The explicit `mut` marker prevents that I don't mutate things by inadvertance, even things I own.
-
woboats
because the rest of your program can't observe the state of your local variables
-
centril
I agree with woboats here; Maybe there should be some way to say that you are not permitted to mutate an owned value, not even by moving..?
-
nox
My years of doing PHP showed me that mutating things that I own can be a logic error.
-
albel727
why "the rest of the program" is to be the ultimate judge of what is useful, again?
-
glandium
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER was the answer to my question, in case someone else was wondering
-
nox
My years of doing Erlang showed me that immutable by default is a very nice way to avoid that whole class of errors.
-
woboats
but its a *local* logic error is the distinction nox
-
nox
woboats: Again, I don't see why that matters.
-
woboats
whereas `&/&mut` is important for nonlocal correctness
-
nox
Why should we kill sometimes that matter for local correctness?
-
» albel727 thought languages are made for programmers, not for "rest of programs"
-
woboats
nox: no one is suggesting "killing" anything
-
centril
woboats: what about wanting to disallow mutation globally so that you can freeze an owned value at some point..?
-
nox
We are suggesting to make `mut` implied.
-
woboats
there's no proposal from removing `mut`
-
nox
There is no RFC, but there are discussions.
-
woboats
there is no momentum behind that idea
-
nox
Good.
-
» centril suspects it would be hard to find consensus for removing 'mut' even with an RFC in any case =)
-
woboats
when I referenced niko's comments, the real point was there are cases where you might actually really *want* to see that mutability, but can't
-
woboats
whereas you are *required* to see it for mutating local values
-
woboats
where it is less useful, because it is *only* local reasoning
-
centril
woboats: what comments are we discussing? got a link per any chance?
-
woboats
i feel like theyve only been made in person, sorry
-
woboats
but consider a function that returns an &mut T
-
woboats
or that takes an Fn(&mut T)
-
woboats
you can use this API without ever using the `mut` keyword
-
nox
centril: SimonSapin started a thread I think. But I may be misremembering.
-
woboats
this mutation involves the interaction between multiple parts of your program, but its "implicit"
-
centril
interesting =)
-
nox
I don't see how the fact that there is sometimes no `&mut` written anywhere is bad means that maybe the required `mut` should be omitted.
-
woboats
nox: its not that its bad, its that we put our attention where it was less important
-
woboats
because we are still learning the nuances of the language that we have already built
-
» centril entertains the idea of let freeze owned_var: T = foo_bar(); with the semantics that you can't &mut owned_var and you can't pass owned_var to anything but a function that acknowledges that the input parameter is frozen
-
nox
That still doesn't make `mut` "silly" in my book.
-
centril
Maybe that idea is a bad one... or interesting..? idk
-
albel727
>freeze <-- iow make mut the default, and constness requiring the keyword. thanks but no thanks :>
-
woboats
albel727: that's not what centril is proposing
-
albel727
oic
-
albel727
forever immutable owned value
-
centril
albel727: yes exactly
-
centril
perhaps it is not that useful..?
-
woboats
centril: it seems a lot like what the Pin type I've been working on for generators does
-
albel727
well most cases I see could be covered with a wrapper struct with Deref
-
woboats
specifically in its stack pinned variant
-
nox
I wonder if `let freeze` would guarantee Drop.
-
centril
woboats: I also had some vague notion that it could be related =)
-
OmniMancer
can't
-
SimonSapin
nox, centril: I have argued informally that `mut` in patterns (like `let mut foo = …;`, not in `&mut _` types) is useless and I’d like to see it made unnecessary to mutate bindings. I have not written any thread or RFC.
-
» albel727 wonders how freezed value would even behave around &mut self in drop()
-
OmniMancer
you let freeze, then the kernel decides you never run again, Drop is now not run
-
nox
SimonSapin: ACK
-
Yaniel
`let freeze` is arguably even more silly since nobody would bother to write it
-
Yaniel
just like `const` in C++
-
nox
OmniMancer: That's different, I don't mind if the program aborts.
-
centril
nox: SYN
-
Yaniel
or if they do, only sporadically
-
nox
Anyway, lunch time.
-
OmniMancer
nox: similar for the kernel decides to never schedule that thread ever again but let the rest of the threads run peacfully
-
SimonSapin
nox, centril: I also *call* `&mut _` and `&_` exclusive/shared references rather than mutable/immutable, but I think it’s probably too late to rename `&mut _` in the language syntax
-
woboats
by about 3 years, SimonSapin ;)
-
nox
SimonSapin: If &mut was &exclusive,
-
nox
I would be arguing for a mechanism to prevent mutation without visual clues.
-
nox
cues*
-
centril
SimonSapin: I think that is right morally, so we can talk about them in exclusive/shared terms
-
albel727
^
-
» centril thinks ^ is somewhat a flawed mechanism =P
-
albel727
:>
-
» albel727 agreed with nox
-
SimonSapin
woboats: I mean we could maybe add a synonym and deprecate the old one at an epoch boundary, but it’s probably not worth the disruption
-
albel727
stupid irc, why doesn't it have happens-before :>
-
centril
albel727: clearly we need fearless IRC ^,-
-
albel727
:D
-
centril
SimonSapin: why do you feel that let mut foo = .. ; is useless?
-
centril
(the mut bit..)
-
SimonSapin
centril: the compiler always know wether it’s necessary or not
-
nox
centril: The reality of it is that we wouldn't be having this discussion if Servo didn't take 15 minutes to build.
-
albel727
>languages are for compilers :>
-
SimonSapin
centril: I regularly make a change or write new code, compile it, and then have to go back to add or remove some mut keywords
-
centril
SimonSapin: well that is true in a lot of cases but we still don't elide... the question should be if removing the need for 'mut' improves readability or not
-
SimonSapin
it’s busy work
-
OmniMancer
SimonSapin: well technically the compiler always knows whether it is required to compile, it doesn't know whether your mutation is incorrect to do
-
woboats
albel727: there's no need to make reductive strawmen of other peoples' positions
-
albel727
no, on the contrary, I quite find it necessary in this case.
-
nox
How is it a strawman to point out that languages aren't for compilers?
-
woboats
because no one claimed that they were
-
SimonSapin
For me personally that compiler error ways "I need to add `mut` somewhere" every single time. I haven’t seen a case where it caught actually-unintended mutation
-
nox
No one claimed that anyone claimed that.
-
SimonSapin
s/ways/is always/
-
centril
SimonSapin: I sympathise but I feel that the core problem lies with compiler performance here... if we improve things and have a neat REPL then that might be less of an issue?
-
woboats
I have the same experience as SimonSapin, but I almost always remember to add `mut` so I don't mind it
-
» centril tries to program in a more functional manner so needs 'mut' less
-
Yaniel
one case that's actually confusing is when you declare a variable, don't mutate it but pass mutable ownership to a function
-
nox
Yaniel: That needs `mut`.
-
Yaniel
and the compiler says you don't need to declare it as mutable
-
nox
Yaniel: No.
-
nox
If you take &mut foo, you need `foo` to be mutable already.
-
OmniMancer
nox: it does not, moving a thing never requires mut
-
woboats
nox: Yaniel said ownership
-
nox
What's mutable ownership then?
-
albel727
having performant compiler and sane IDEs would preclude having so many arguments. like >let's pull the python 2/3 split stunt on the module system because use statements were mutilated, because :: prefix was considered too heavy to type (even though it's a great entry point for completion in any IDE, not to mention that use statements can be added automatically), and we don't want to fix "use"
-
woboats
the thing is that there's no such thing as "mutable ownership"
-
OmniMancer
&mut requires it
-
nox
Ah, ok.
-
OmniMancer
but moving it into the function and the function mutating it is not needing mut
-
woboats
the fact that you put `mut` on the function argument makes it seem like its a different kind of ownership
-
centril
woboats: yeah, I misread what Yaniel said too
-
woboats
especially since there's the connection to `&` and `&mut`
-
nox
OmniMancer: You gave up ownership of it,
-
nox
why would it need to be mutable?
-
OmniMancer
nox: indeed
-
SimonSapin
centril: even with better compiler performance it’s still busy work IMO
-
nox
OmniMancer: Oops sorry confused you with Yaniel who made the original point in this discussion.
-
woboats
when you can do `let vec = vec![]; let vec = foo(vec);`, but `foo` mutates it, the notion of "immutability" seems a bit stretched
-
centril
SimonSapin: sure; some busy work may be acceptable tho for improved readability - there's the trade off btw writing and reading and I tend to favour reading
-
nox
woboats: I don't see how.
-
nox
If I sell you my phone, why would I care that you mod it afterwards?
-
woboats
because of shadowing, you can't actually assume that because you see an immutable `let` binding, that name refers to the same thing every time you see it
-
nox
Yes I can assume that.
-
woboats
well what specifically do you see as the benefit of knowing a variable is immutable, nox?
-
SimonSapin
right, and then we get into subjective judgment of how much is readablity improved by this
-
woboats
you *can't*, unless you've confirmed its not shadowed between that binding and this location
-
nox
woboats: That I can't mutate it.
-
nox
If I see a variable used, I can go upwards to find where it was defined,
-
albel727
(1 click in an IDE)
-
nox
and if there is no mut I can be sure it wasn't mutated, barring interior mutability.
-
» SimonSapin goes get lunch, bye all
-
nox
albel727: Yeah, that too.
-
woboats
unless you've missed a `let` binding
-
nox
Why would I?
-
centril
SimonSapin: can't argue with that... eventually things get subjective, but I think that doing nothing should be our default position and doing something has the burden of proof
-
nox
If I focus a word in my editor it highlights every single occurrence of it.
-
centril
in the general case
-
woboats
nox: your IDE could also highlight every mutation
-
nox
With way more tooling.
-
centril
SimonSapin: bon apetit
-
nox
And that means I need the IDE to review the code.
-
nox
Or to comprehend it.
-
nox
Then I can't do anything on my phone.
-
woboats
It isn't my experience that I can't comprehend code without the `mut` keyword
-
nox
It is my experience that implicit mutation caused issues for me without explicit visual cues.
-
woboats
but as I said, I never get errors about needing to add the keyword either, so I don't mind it existing for people with a different experience
-
centril
woboats: I agree; but 'mut' let's you see easier when mutation is going on imo
-
centril
s/easier/quicker
-
woboats
In contrast, its my experience that *aliased mutation* causes hard to solve bugs & technnical debt, so I think its very important and great that Rust solves that problem
-
nox
Exactly, just because shadowing can make you miss some doesn't mean you should just allow all mutations all the time on owned things.
-
albel727
^
-
woboats
I'd like to know if we all felt the same way about "implicit mutation" if we had access to a language where mutation was implicit, but never aliased
-
nox
I have access to a language where there is no mutation, and I had way less errors due to implicit mutations (heh) than I had in PHP with it. And I was more confident about my own reviews in it.
-
centril
woboats: Personally I always prefer functional programming and not mutation (acceptable as optimization), so I wouldn't be in favor of it personally
-
» albel727 doesn't think it's only the aliased mutation that was the source of bugs in his experience
-
nox
albel727++
-
albel727
not to mention that having a variable binding immutable sort of puts an upper bound on complexity of control flow around it.
-
woboats
albel727: could you elaborate? i dont know what you mean
-
OmniMancer
things that don't change can't cause confusing loop termination conditions
-
albel727
^
-
albel727
e.g
-
albel727
I was typing my examples, so thanks for saving me the effort and putting up a concise example
-
woboats
But they can be changed through shadowing
-
OmniMancer
not in a loop in rust
-
woboats
I suppose the thing is that doesn't impact things like `while` headers
-
albel727
anything you can shadow in the loop stays in that loop only
-
albel727
when you have a variable and a loop, it's immediately more liberating to see that it's immutable, because you know that however weird things are going in the loop, they don't accumulate chaos through the external binding.
-
woboats
but you could easily do `let x = 0; loop { let x = rand(); if x != 0 { break; } }`
-
Yaniel
sure
-
Yaniel
now do it accidentally
-
albel727
I think the key point is >accumulate chaos
-
albel727
you can do chaos in the loop, but it never becomes so unpredictable as you have to reason about N+ iterations of the loop.
-
woboats
The notion of accumulated chaos is interesting
-
centril
Yeah
-
woboats
Well you have to reason about it for every mutable variable outside the loop, but not for the immutable variables
-
Yaniel
so now you have to either remember which ones you have to care about or which ones you don't have to care about
-
albel727
yeah. which is why dwindling mutable variable numbers is a good thing. and immutable-by-default bindings is the only thing that lets to do that in practice.
-
woboats
it makes sense as a way to mitigate complexity
-
albel727
it makes a whole world of sense, especially when reading code, kindly believe me on that.
-
OmniMancer
I feel like most things that improve readability at some point could be considered "unnecessary"
-
albel727
yeah, when AI comes by :>
-
OmniMancer
doesn't make Perl code any easier to reason about
-
nox
OmniMancer: Yeah that makes me sad.
-
albel727
you don't need to reason about it. you just tell AI to do things, and it does. until one day it hates you so much for having to read perl code, that it ends humanity. the end. :>
-
OmniMancer
Oh also a bunch of features I see evaluated for how they affect existing code or writing code
-
OmniMancer
but not for how they affect you changing code that already exists that you may not fully understand
-
woboats
OmniMancer: that is actually a huge influence on our decision making
-
OmniMancer
woboats: I imagine it is, but it does not always seem to be considered this way when RFCs are discussed
-
OmniMancer
but that is just the feeling I get sometimes from reading some comments and I have not looked at RFC discussion in ages
-
woboats
its hard to develop a shared language we can use to talk about that kind of situation
-
centril
woboats: neat emoji on I-unsound =P
-
» centril goes and looks for an ice emoji for I-ICE ^,-
-
woboats
centril: dont add any more
-
woboats
centril: unfortunately it changes the URL
-
centril
woboats: o.O how unfortunate
-
» centril was joking tho =P
-
woboats
hoping no one is tracking the I-unsound tag in any documents, but it might have to get changed back
-
woboats
definitely there are other tags it would be very disruptive to add emoji to
-
centril
woboats: too bad you can't have emoji + separate slug
-
centril
separate url-slug*
-
woboats
yea :-\
-
centril
woboats: maybe emoji in description?
-
woboats
figured adding a joke to I-unsound would be lighthearted w/o going overboard
-
centril
woboats: It was a nice one!
-
woboats
it also emphasizes that I-unsound is sort of the worst kind of bug
-
centril
woboats: Yeah, I wanted to communicate that but really couldn't find the right words
-
centril
but an image says more than...
-
» centril learned a lot by giving the labels descriptions
-
nox
woboats: I put dragon emojis in my commits that require extensive unsafe review.
-
nox
-
nox
Join the dragon train too!
-
centril
Look... some ❄️ (ICE)
-
nox
Where is Yuri?
-
centril
meh... what a gigantic bummer, I can't use 🐢 (turtle) for I-slow
-
lgspaw
play.integer32.com/?gist=3310dda3b5…9d1bfd762558e5ded49&version=nightly im struggling with this error, ive got a feeling i need to have two lifetimes
-
panicbit
oli_obk_: Is there are reason for why the features field (and a few others) in cargo_metadata::Dependency is private?
-
panicbit
-
nox
centril: Why not?
-
oli_obk_
panicbit: not really... noone needed them and it's backwards compatible to make them public
-
panicbit
Cool
-
panicbit
I'll make them public then :)
-
oli_obk_
ok
-
centril
nox: above 0x... something something =)
-
scoopr
1
-
gnzlbg
SimonSapin: > but I think it’s probably too late to rename `&mut _` in the language syntax
-
gnzlbg
we have epochs now
-
gnzlbg
& and &exc might be better
-
gnzlbg
or &ex
-
gnzlbg
or similar
-
oli_obk_
gnzlbg: that seems very counterintuitive... I have no clue what `exc` would mean
-
gnzlbg
mut in patterns and mut in references are just two different things
-
gnzlbg
oli_obk_: I am bad at naming
-
gnzlbg
but arguably it is better to not know what something means and look it up
-
gnzlbg
than to be wrong about what it means
-
nox
It's not wrong to consider &mut to be about mutation though.
-
nox
centril: Wait what, GH doesn't even handle Unicode correctly?
-
OmniMancer
I am still a bit worried about epochs :/
-
albel727
well, one can see how &mut and &exc can be not exactly the same. current &mut T is like &exc mut T, and the question is if "&exc T" to mean "a borrow that is guaranteed to be exclusive, but without ability to mutate" is a useful thing to want to express. if not, then conflating "&exc mut" to just &mut like it is now doesn't seem to be wrong.
-
gnzlbg
nox: mutation follows from exclusive access, not the other way around
-
nox
gnzlbg: That doesn't change what I said.
-
panicbit
OmniMancer: If they don't turn out to be good we can just release a new epoch without epochs ¯\_(ツ)_/¯
-
gnzlbg
nox: & has nothing to do with mutation though
-
nox
And?
-
gnzlbg
&mut => mutation would imply that & => no mutation
-
gnzlbg
which is wrong
-
nox
& => immutable &mut => mutable is still a very good simplification.
-
OmniMancer
it doesn't have nothing to do with mutation
-
nox
OmniMancer: Yep.
-
OmniMancer
it just has a complicated relationship with mutation
-
nox
Don't we all have
-
OmniMancer
&mut guarantees it is mutable
-
OmniMancer
& might be mutable depending on the type
-
gnzlbg
nox: like all imperfect simplifications, it works till it breaks
-
albel727
wait, "& => no mutation" seems to me pretty correct here. interior mutability is just a hack from the impure real world.
-
nox
So what's your point?
-
nox
albel727: Some people argue that `mut` is useless because "what about interior mutability".
-
albel727
._.
-
gnzlbg
and no aliasing
-
gnzlbg
(amongst other things)
-
nox
Aliasing doesn't matter for logic errors.
-
OmniMancer
I don't think even with epochs it is worth changing
-
gnzlbg
if you want __restrict you use &mut
-
nox
OmniMancer++
-
gnzlbg
independently of whether you want mutaiton or not
-
OmniMancer
making all documentation and resources about rust wrong again after 1.0 would be very bad
-
gnzlbg
nox: I wasn't arguing that mut is usless, I was arguing that mut is not the best name
-
gnzlbg
and that now we have epochs for syntactic changes
-
nox
gnzlbg: But if mut wasn't named mut, I would be arguing for an additional thing named mut to explicitly state one wants mutation.
-
SuperFluffy
When I started out, Cell and RefCell really confused me. I always wondered, if this was a concept unique to Rust, or do other languages have this, too?
-
gnzlbg
nox: let mut x would still be a thing
-
albel727
he would be arguing for &exc mut thing
-
nox
gnzlbg: Why would `let mut` allow one to call `&exclusive self` methods, then?
-
gnzlbg
then i would be arguing that mut there is not necessary
-
OmniMancer
gnzlbg: so then the question would be why can't I take &exc of a thing that isn't declared mut
-
gnzlbg
nox: sure
-
nox
OmniMancer: Oh yeah, you phrased that better.
-
OmniMancer
gnzlbg: most things are not necessary
-
albel727
wait, you won't be arguing against "let mut", but would be arguing against "&exc mut T"? how is that consistent?
-
gnzlbg
OmniMancer: gotchat
-
OmniMancer
for some definition of necessary
-
gnzlbg
i see the motivation for &exc mut
-
gnzlbg
and &exc
-
nox
I think `let mut` allowing one to call `&mut_not_named_mut self` would be even more confusing that the current state.
-
gnzlbg
idk, maybe
-
gnzlbg
rust currently doesn't allow no aliasing + no mutation
-
OmniMancer
I still think that even with epochs they should not be an excuse to tinker with things that already exist and work fine but some people don't like the nomenclature
-
gnzlbg
OmniMancer: I have a lot of code that uses &mut for: no aliasing + no mutation
-
OmniMancer
changing the syntax for things that already exist has non trivial costs
-
gnzlbg
because &mut is the only way to get no aliasing
-
gnzlbg
"a lot", more like, "some code"
-
albel727
do you have an example? I was kind of were aiming for those, when I posed a "if &exc mut T is a useful thing to want to express" question before.
-
gnzlbg
I use it in kernels to express __restrict
-
albel727
s/were//
-
gnzlbg
even if I am only reading from a variable
-
OmniMancer
I see epochs as a useful tool for adding syntax that is technically a breaking change, not as an excuse to rewrite the whole syntax of the existing language arbitrarily
-
albel727
well, maybe introduce a third kind of borrow, &exc, then. making everyone write "&exc mut" to mean "&mut" would be penalizing the most common case.
-
rkruppe
OmniMancer: Mostly agreed. Though introducing dyn and eventually deprecating dyn-less trait objects is useful IMO, so not a hard rule
-
centril
-
centril
albel727, nox, woboats, et al. ^
-
nox
ajeffrey: ^
-
OmniMancer
rkruppe: there may be exceptions yea, not sure how I feel about the dyn thing
-
Xion_
centril: What a communist idea. If you own something, you should be able to do whatever you want with it ;p
-
centril
Actually writing this down made me think about the rules involved =P
-
centril
Xion_: so you are saying steveklabnik and I would approve =P
-
OmniMancer
but in general a way to make breaking syntax changes is not license to break all the syntax constantly without having a very very good reason
-
nox
centril: Salut camarade.
-
rkruppe
centril: What's the motivation?
-
centril
rkruppe: nothing specific right now, it was a #rust provoked idea
-
centril
see discussion above and backlog
-
nox
centril: I'm having fun with types today.
-
nox
-
centril
nox: Debout, les damnés de la terre; Debout, les forçats de la faim...
-
centril
=P
-
gnzlbg
so how would we introduce an exclusive non-mut borrow?
-
rkruppe
centril: My gut feeling is that this is a lot of machinery and a lot of limitations for something that has no good use at all
-
gnzlbg
&mut non_mut foo ?
-
nox
centril: ✊
-
gnzlbg
or &mut_non_mut foo
-
centril
nox: weechat didn't render that correctly :(
-
nox
centril: Fix your client. :p
-
gnzlbg
maybe &mut_immutable
-
gnzlbg
rkruppe: hi
-
centril
rkruppe: hence: "These are just some vague ideas at this point and may be wholly useless or very not nice to work with" =P
-
nox
centril: U+270A RAISED FIST
-
rkruppe
gnzlbg: hi
-
centril
nox: ah, cool =P
-
albel727
>a frozen T is a subtype of T <-- wait, how is that correct. you can't pass a value of frozen T to anything that takes T.
-
gnzlbg
I started trying to figure out how to do the multiple source compilation in rustc
-
centril
albel727: oh yes, that is not correct
-
gnzlbg
*single source, multiple targets
-
rkruppe
centril: Sure
-
centril
albel727: the reverse is tho - T <: frozen T
-
albel727
yeah
-
centril
albel727: fixed, thanks
-
OmniMancer
gnzlbg: &&mut T :P
-
albel727
V:
-
albel727
(well, that one is clever, but unfortunately still effectively the same as &T, wrt aliasing)
-
OmniMancer
albel727: the inner reference is unaliased
-
OmniMancer
oh wait no
-
OmniMancer
yea not useful :P
-
OmniMancer
well except that it guarantees the inner referrent had no & refs at the time the &mut was made
-
albel727
yeah, it has no & refs for the duration of inner &mut lifetime... but now has a bunch of &&mut refs :>
-
centril
nox: type hackery is always fun
-
OmniMancer
does &mut&&mut T work though?
-
albel727
so you have a &mut to *one of* the &&mut T refs. fascinating :>
-
albel727
now you can show that ref, who's the boss here <:
-
» albel727 hides
-
OmniMancer
I guess if you have an operation that takes the &mut T and manufactures the &mut&&mut T directly it will be unaliased, but otherwise not
-
nox
-
albel727
yeah, as a matter of raw fact. but the point is also to make that information available to the compiler at all places of use, so that it can make optimizations. and if you write your function signature like fn blah(arg1: &mut&&mut T, arg2: <same>), it in general can't deduce that arg1 != arg2
-
nox
albel727: In some part of Servo, I'm currently passing a glorified &mut &'a UnsafeCell<T>.
-
centril
nox: beautiful, but Sean Griffin likes em more
-
rkruppe
albel727: huh? arg1 and arg2 absolutely must be distinct. (the innermost &mut can be aliased, ofc, since it's behind a &)
-
centril
nox: nice use of the Length<Kind>: Storage thingy
-
nox
centril: So I tried to be a mechanical turk when I wrote the TCV impl for Length<Kind>,
-
albel727
rkruppe: yeah, it was roughly speaking. of couse I was meaning the innermost one.
-
albel727
*course
-
nox
centril: and I forgot ` Length<<Kind as ToComputedValue>::Output>: Storage`,
-
nox
but I think this one can also be D E D U C E D automatically by the deriving code.
-
centril
nox: methinks that is right
-
nox
centril: The back story is that Stylo has insane amounts of generics,
-
nox
centril: just because many things have different representations whether they are specified or computed values.
-
» albel727 is sure this isn't the first time something like &exc is being discussed anyway, so there's no point wasting time on it :>
-
nox
We currently have one type param per thing which representation vary depending on the kind of values in the structure,
-
nox
trying to make that a single type param marker.
-
centril
nox: btw, you can do type Foo<K> = <K as ToComputedValue>::Output;
-
centril
which is pretty neat
-
nox
centril: Yeah I know, but this is supposed to be behind a derive anyway. :)
-
centril
=)
-
nox
centril: I guess that may make the docs look better though…
-
centril
nox: yeah
-
nox
-
nox
If I can make that Gradient<Specified> -> Gradient<Computed>, I'll be pretty hyped.
-
centril
nox: oh holy mother of...
-
nox
centril: Heh. :D
-
OmniMancer
nox: Generics for the Generic god, constraints for the constraint throne?
-
nox
centril: #[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf, Parse, PartialEq, ToAnimatedValue, ToAnimatedZero, ToComputedValue, ToCss)]
-
centril
nox: I'm assuming you guys are pretty stoked about impl Trait
-
nox
centril: Not even, this is all derived so we don't care.
-
centril
but still... makes docs more readable
-
nox
centril: Well where would they here, though?
-
nox
We store all kinds of values, specified, computed and animated, so we need them types to be concrete.
-
albel727
>inb4 naming types by return type of a function name
-
centril
nox: oh it doesn't apply here I think... but type CV<TCV> = <TCV as ToComputedValue>::ComputedValue; would help a lot in this particular link
-
nox
centril: Yeah I agree.
-
centril
would reduce reading complexity to half I think
-
Xion_
Nice #[derive]
-
Xion_
Maybe there should be a convention that in derives like this, you should order the traits like you'd order imports: standard ones first, then third-party ones, then own project's ones.
-
albel727
there usually aren't that many, that lexicographical order doesn't work.
-
centril
albel727: +1
-
Xion_
n.b. "like this"
-
nox
-
Dani
heya
-
oli_obk_
locals, conditions, loops... anything else on the const eval wishlist?
-
centril
nox: "Kind" is giving me HKT vibes =P
-
nox
centril: The names are bad.
-
nox
centril: Not sure which one I prefer between the two.
-
nox
(The two playgrounds, not talking about naming.)
-
nox
The latter is simpler,
-
nox
but Length<Computed> looks better than Value<SpecifiedLength, Computed>.
-
centril
nox: idk, I can't put it in the proper context to judge =)
-
Mateon1
Hi, what should I use for a filesystem-backed set of hashes? (literally a set of md5 hashes). I need quick "add" and "contains" operations. Is there anything more lightweight for this than a full database?
-
rkruppe
Mateon1: md5 hashes are very small, are you sure you need to to be backed by the file system?
-
nox
-
Mateon1
rkruppe: I definitely need it to be saved to persistent storage, I'm not sure if serializing it on program exit is good enough. I expect to store a few million hashes at a time
-
nox
Mateon1: Is that for Servo fuzzing, my hero?
-
centril
=)
-
rkruppe
Mateon1: Serializing on exit and deserializing at startup seems much simpler than maintaining a file during operation (and likely easier to make fast too, unless you do only a few operations per run). A few million hashes is dirt cheap -- in the order of MBs
-
Mateon1
nox: Yes, I'm running into problems with constantly repeating reductions I've already tried. I could improve effective performance possibly 10x
-
sgflt
is there currently any way to pass two different Fn-trait implementing functions to .filter() ?
-
sgflt
apparently, Box<Fn> does not implement Fn yet?
-
ishitatsuyuki
Huh?
-
rkruppe
sgflt: &Fn implements Fn though
-
sgflt
rkruppe: ah, thanks
-
Mateon1
rkruppe: Yeah, I see. That's probably fine for a few million, that fits in 100 MBs even. A BTreeSet will probably be fine
-
sgflt
rkruppe: still can't pass that to .filter though, i think
-
rkruppe
sgflt: Why not?
-
nox
sgflt: You can pass &your_boxed_closure.
-
sgflt
how am i supposed to read that: : std::ops::Fn<((std::string::String, std::string::String),)>` is not satisfied
-
sgflt
the extra , in there is driving me a bit crazy
-
nox
sgflt: Show us the code you wrote.
-
sgflt
nox: i'll put it up on the playground, 1 sec
-
nox
Seems like you wrote Fn<(String, String)> instead of Fn(String, String) or something like that.
-
nox
Err no, maybe the opposite rather.
-
Xion_
You tried to call a binary function with a pair instead of two arguments
-
sgflt
-
sgflt
whoups, that is supposed to be filter_map
-
nox
sgflt: s/FnMut/Fn/ for starters.
-
nox
sgflt: You either make a Box<Fn> and borrow that immutably,
-
nox
or you make a Box<FnMut> and borrow that mutably,
-
nox
but an immutable Box<FnMut> is useless.
-
sgflt
right
-
sgflt
that does not seem to affect the issue with the missing trait implementation though, if i am not messing this up elsewhere
-
nox
It does.
-
nox
-
nox
-
sgflt
so the &* cast was missing?
-
nox
sgflt: Yeah. Either &* with Fn or &mut * with FnMut.
-
sgflt
nox: thanks
-
cmyr
is it kosher in a build script (for a -sys crate) to download a tarball to build from source?
-
sgflt
cmyr: that would make me sad, since it prevents me from rebuilding when working offline
-
oli_obk_
cmyr: why don't you just add the source you need as a submodule?
-
oli_obk_
then it'll be in the crates.io project
-
cmyr
oli_obk_: the source I'm looking at (for gdbm) is harder to build from the cvs source than from the tarball
-
cmyr
the tarball already has the ./configure script set up
-
centril
oli_obk_: const effect polymorphism thank you =)
-
nox
cmyr: No.
-
centril
but that mostly depends on me fixing up my RFC one day
-
oli_obk_
centril: wat is that?
-
nox
A build script ain't supposed to download stuff.
-
centril
oli_obk_: some modified version of:
rust-lang/rfcs #2237
-
nox
cmyr: Just vendor the code in your own crate.
-
cmyr
hmm, but what about a buildscript (like for libgit2-sys) having an external submodule?
-
cmyr
yea alright
-
nox
centril: In my second playground, I guess I can do type Length<Kind> = Value<SpecifiedLength, Kind>.
-
centril
nox: that is nice =)
-
centril
oli_obk_: "for loops are technically allowed, too, but can't be used in practice because each iteration calls iterator.next(), which is not a const fn and thus can't be called within constants" <-- how sad; my RFC aims to fix that.
-
oli_obk_
centril: ah :)
-
oli_obk_
cool
-
oli_obk_
I'll have a look
-
oli_obk_
centril: miri-wise this won't be a problem
-
centril
oli_obk_: I haven't updated it in months, so be sure to read the discussion, especially eternaleye's comments for the current thinking
-
centril
oli_obk_: =)
-
nox
-
nox
centril: Don't actually need Value<T, Kind>, PogChamp.
-
nox
centril: What do you think of s/Kind/Family/?
-
j_ey
trying to 'impl<'a> From<&'a [f64]>', and then Im calling &vec.into(), but that doesn't seem to work. 'the trait `std::convert::From<&std::vec::Vec<f64>>` is not implemented'
-
nox
j_ey: (*vec).into()
-
j_ey
ah
-
nox
j_ey: Or use From.
-
j_ey
From::from(vec) ?
-
nox
j_ey: Nah, with the explicit result type instead of From,
-
j_ey
I dont quite get why *vec works
-
nox
to nudge type inference a bit.
-
nox
j_ey: Because the type checker had not enough info for the inferenec.
-
nox
'inferenec' looks cool, but I meant inference.
-
j_ey
sorry, not quite sure what you mean with 'with the explicit result type instead of From'
-
nox
j_ey: Vec::from(&vec) if you wanted to build a Vec<T>.
-
j_ey
ahh
-
j_ey
Stats::from(&*times) this works too
-
centril
nox: Kind seems better - but I think you will end up with a generic name
-
centril
and that is fine
-
nox
centril: I thought "type family",
-
nox
centril: but not sure which one is the biggest misuse between Kind and Family. :D
-
centril
nox: I think the misuse is on the Haskell side calling types of types "kind"
-
centril
Agda does this better and less confusingly
-
centril
but then Agda is also consistent as a logic and you don't have * :: * so it has to be less jumbled and confusing
-
centril
oli_obk_: left you a bunch of review comments on your loop rfc =)
-
nox
centril: You just reminded me Hewitt's "maths are self-consistent", pls no
-
rkruppe
one of my favorite things about the Rust community is that I'm not alone in having suffered through Hewitt
-
rkruppe
I'm only half joking
-
centril
nox: Curry-Howard is beautiful
-
oli_obk_
centril: thx, I'll address whatever I didn't comment on ;)
-
centril
It let's programmers claim they are mathematicians
-
nox
rkruppe: Ah ah.
-
centril
oli_obk_: I think I got rickrolled by a stack-overflow question on #[recursion_limit = "<limit>"] =P
-
centril
-
centril
-
nox
centril: Do you know of code similar to the playground I linked with the Kind stuff btw?
-
rubdos
There's `move || {}`, but how can I clone a value into a closure, instead of moving?
-
rubdos
some nice syntax for that too?
-
rkruppe
No special syntax, create a clone manually outside the closure and use that in the closure
-
rubdos
okay
-
rubdos
was about to do that, but couldn't hurt to ask
-
Mateon1
Oh my god this is frustrating. I can't think of a way to pass a clone of a certain struct to hyper, cause .bind() takes a Fn() -> T, and any outside cell "may outlive" main
-
Mateon1
I also tried extremely unsafe raw pointer manipulation, but I failed at it
-
centril
oli_obk_: nice changes in the motivation
-
Mateon1
I think I need a Cell that is Copy
-
centril
-
centril
maybe not...
-
centril
the term Repr reminds me of that tho
-
sgflt
can someone recommend a web framework "most like rocket.rs, but compiles on stable"?
-
stephaneyfx
I cannot recommend it because I have never used it, but there's {!crate gotham}
-
rustbot
gotham (0.1.2) - A flexible web framework that does not sacrifice safety, security or speed. ->
crates.io/crates/gotham <
docs.rs/gotham>
-
Mateon1
I'm trying to solve this:
play.rust-lang.org/?gist=d66e676af6…09e408121374e54c4251&version=stable - How can I pass a shared Service to hyper's .bind() method?
-
wrl
sgflt: i really like {!crate shio}
-
rustbot
shio (0.3.0) - Shio is a fast, simple, and asynchronous micro web-framework for Rust. ->
crates.io/crates/shio <
docs.rs/shio>
-
sgflt
shio and gotham are on my shortlist as well, thanks
-
Mateon1
Ok, I give up on Hyper, moving back to Rocket
-
pickfire
docs.rs/shio doesn't look nice.
-
Jasmine
How can I have cargo doc not omit the fields for a struct?
-
xrl
any tips on how to track down a memory leak in my tcp server? I think it might be some futures channels not closing all the way or I'm leaking threads (spawned for each client). I think it might help to name my threads but I can't get prctl::set_name() to work. it'd be great to look at htop and see what the threads are for.
-
stephaneyfx
Jasmine: It won't omit them if they are pub
-
Jasmine
stephaneyfx: They are pub
-
Jasmine
pub struct LoginRequest { /* fields omitted */ }
-
Jasmine
from the generated docs^
-
stephaneyfx
Jasmine: Hmm weird, they should show up then
-
Jasmine
oh wait im an idiot, sorry. The fields on the struct have to be pub, not the struct itself
-
nox
centril: Reading about type families, the word Family seems to fit more than Kind.
-
nox
centril: trait Family<Index> { type Type; }?
-
rovar
is the users.rust-lang.org login-via-github link broken for anyone else?
-
nox
rovar: GH is in unicorn mode, so things may be broken.
-
rovar
ah
-
rovar
I did a quick load of a gh project and it worked, so suspected no angrycorns
-
ryanlevick
Hello! Is there a way to apply a procedural macro on an imported type?
-
udoprog
So I'm having issues unpacking a `Cow<'a, str>` and translating it into another `Cow<'a, str>` through as_ref() (loses track of lifetime). But not when I do the same as an expression. What Am I missing?
play.rust-lang.org/?gist=ebc4ea3ec4…d757b0cbd5b79985661b&version=stable
-
udoprog
(Primarily the second part, I can reason that as_ref() doesn't include the lifetime in the signature)
-
talchas
udoprog: the issue is that Cow could be Cow::Owned
-
talchas
ie, it would be String
-
talchas
and in do_stuff it is then dropped at the end of the function
-
nox
centril: What about s/Repr<Kind>/Instance<Family>/?
-
nox
Nah that's not it.
-
talchas
in main(), it works because s is dropped after c would be
-
udoprog
talchas: Yeah, so the compiler understands that is not the case statically in the expression?
-
SimonSapin
oli_obk_: soon: "make all of libcore const fn" :)
-
talchas
no, it's just that you aren't consuming s
-
centril
nox: oh my... I've been reading
lambda-the-ultimate.org/node/4784 for a long time now
-
centril
what have you done to me =P
-
nox
centril: AH AH AH AH AH
-
talchas
the standard solution here is that you'd pass and return &str in do_stuff, not Cow
-
centril
nox: this Hewitt fellow...
-
nox
centril: I was wondering why you had disappeared.
-
centril
nox: =P
-
centril
"Where Hewitt crosses the line from interesting observation to (sorry) crackpot theory is in turning the correct observation around. ASSUMING proof by contradiction is valid THEREFORE mathematics is consistent. Sure, that's also true, and I accept he has proven this is true ... but he hasn't proven that proof by contradiction is valid in the first place! Everyone else can assume this for the
-
centril
reasons stated above (sure, my theorem may in future be invalidated by a proof that all of mathematics is inconsistent, but I can live with that). But someone who is trying to PROVE that mathematics is consistent cannot ASSUME that proof by contradiction works."
-
centril
"So yes, the argument is circular. IF mathematics is consistent THEN proof by contradiction is valid THEREFORE mathematics is consistent."
-
centril
that is pretty apt
-
udoprog
Yeah, of course. Thanks talchas!
-
forgottenone
how can i create a trait object points to null
-
Xion_
centril: something something Goedel incompleteness theorem
-
» albel727 wonders why would one want a trait object pointing to null
-
centril
Xion_: the most unsatisfying result ever =P
-
forgottenone
albel727: i'll use it for pointer comparision
-
forgottenone
in ptr::eq
-
albel727
hmm
-
albel727
I hear std::ptr::null() was going to have where T: Sized restriction lifted
-
albel727
but I'm not sure what it means wrt virtual table pointer and such
-
talchas
you can also just do
-
talchas
eval: use std::any::Any; let x: *const i32 = std::ptr::null(); x as *const Any
-
eval
0x0
-
talchas
and that will have the vtable of i32-Any
-
albel727
much fun
-
talchas
now, if you deref this to invoke a &-method, that is UB, because you have &something pointing to null
-
albel727
but the comparison with a trait object of unknown type probably compares virtual tables too, I guess?
-
talchas
ptr::eq is presumably fine
-
albel727
hmm
-
» albel727 goes to read the docs
-
talchas
eval: use std::any::Any; let x: *const i32 = std::ptr::null(); let x = x as *const Any; let y: *const u32 = std::ptr::null(); let y = y as *const Any; std::ptr::eq(x, y)
-
eval
false
-
talchas
yes, it compares vtables
-
albel727
eval: --nightly use std::any::Any; let x: *const i32 = std::ptr::null(); let x = x as *const Any; let y: *const u32 = std::ptr::null(); let y = y as *const Any; std::ptr::eq(x, y)
-
eval
false
-
nox
eval: --nightly use std::any::Any; let x: *const i32 = std::ptr::null(); let x = x as *const Any; let y: *const u32 = std::ptr::null(); let y = y as *const Any; std::ptr::eq(x as *const (), y as *const ())
-
eval
true
-
albel727
so that's how you extract the data pointer
-
albel727
by casting to a thin pointer
-
edd
I don't understand why when I have in build.rs: println!("cargo:rustc-link-lib=ipt");
-
albel727
so the answer is not to build trait pointers but just cast existing trait pointer to thin and compare with ptr::null()
-
edd
my examples link -lipt fine, but my tests dont
-
albel727
forgottenone: ^
-
albel727
hmm, wait, why is it even necessary
-
albel727
if there's .is_null()
-
albel727
eval: --nightly use std::any::Any; let x: *const i32 = std::ptr::null(); let x = x as *const Any; x.is_null()
-
eval
true
-
albel727
forgottenone: ^?
-
forgottenone
albel727: is_null wont do, since i use trait object equality to skip objects in a vector, but casting trait objects to thin pointer makes sense
-
phaazon
hey
-
forgottenone
albel727: talchas: thank you
-
albel727
nox too
-
albel727
(basically it's his answer :>)
-
phaazon
is there a rustc flag to tell it where to find files (for use statement)?
-
forgottenone
albel727: yeah i missed his answer, thank you nox
-
albel727
I thanked him for you. now he has one excess thank. quick, take it back.
-
albel727
use statement can only use things from existing module hierarchy, I think?
-
albel727
it's not like include in C
-
albel727
(where you have include dirs and suchlike)
-
talchas
#[path="whatever"] mod foo; lets you specify a different name/location
-
» albel727 was getting to that :>
-
albel727
thanks for sparing me the trouble :>
-
talchas
but you shouldn't use that to include library code or things like that
-
Aadi
hi
-
centril
Aadi: hello there
-
nox
centril: A friend suggested trait FamilyInstance<TypeFamily>.
-
nox
"a family instance parameterized by a type family"
-
centril
nox: hmm... trait MyTypeFamily { type Output; } impl MyTypeFamily for usize { type Output = bool; } corresponds to type family MyTypeFamily (self :: *) :: *; type instance MyTypeFamily Int = Bool ;
-
nox
centril: Hence the 'instance'.
-
centril
nox: type families are type level functions, but you are making a trait parametric over a type TypeFamily
-
centril
type families correspond to traits
-
nox
centril: The encoding reverses the things.
-
centril
nox: the encoding would correspond to: type family FamilyInstance (self :: *) (typeFamily :: *) :: *
-
centril
but this naming seems unhelpful to me
-
centril
(aside note: Rust does not support provide a fallback _ => MyType default case in type level functions yet, but specializing associated types would allow that...)
-
nox
I read impl FamilyInstance<Specified> for SpecifiedLength as an instance of the Specified family for SpecifiedLength.
-
nox
Not encoded at all the way it should, but the words seem to fall at the right place to me.
-
albel727
>tfw there's no link to beta/nightly stdlib on docs.rust-lang.org front page ._.
-
albel727
>not even links for different stable releases
-
albel727
where google takes them, I wonder
-
Xion_
Magic.
-
centril
nox: but this encodes __all__ unary type families using a binary type family with an index type for each family as the second parameter
-
centril
nox: what you are doing makes sense, but the TypeFamily parameter feels ill-named
-
halfbit
excited for when emacs and rust lsp work super well
-
nox
I consider the impls of the trait to be the instances of the type families, and the type families exist only by the fact that the trait is implemented. Does that make sense?
-
nox
centril: If you have a better name suggestion I'm all ears, but I took note.
-
centril
nox: Kinda - in this case, FamilyInstance<Specified> denotes a type family * -> * by fixing the binary type family * -> * -> * with Specified :: * so you get * -> * back
-
nox
Yes, I see what you mean.
-
centril
nox: given this; I'd name it as such: trait BinaryFamily<Rhs> { type Output; } impl BinaryFamily<Specified> for SpecifiedLength { type Output = ... ; }
-
centril
or just trait Family<Rhs> { .. }
-
nox
Why Rhs?
-
centril
even: trait IndexedFamily<Index> { .. }
-
centril
nox: right hand side of a binary type level function
-
nox
centril: But SpecifiedLength isn't the family.
-
centril
nox: no, the family is BinaryFamily
-
nox
Ah I see what you mean.
-
centril
nox: you might not want the full generality in naming, so trait Family<Index> { .. } might work better
-
nox
You put more importance to the meaning of Trait on its own, while I put more importance on Trait<T> I think.
-
centril
nox: sure, under the interpretation that you can partially apply the "right hand side" T parameter, fixing the binary type family Trait with Trait<Foo> gives a unary type family =)
-
centril
but nonetheless, a FamilyInstance is an impl =)
-
nox
-
centril
nox: sure why not, if Phased is accurate for your domain which I assume it is =)
-
nox
-
centril
-
nox
centril: Sent it on #servo, thanks for participating to the bikeshed. :)
-
centril
nox: it was fun =)
-
centril
nox: I think the type aliases type CV<TCV> = <TCV as ToComputedValue>::Output; type AV<TAV> = <TAV as ToAnimatedValue>::Output; can really make a difference =)
-
nox
Yeah.
-
centril
makes traits feel much more like "normal fn"s
-
boomshroom
Hello!
-
mbrubeck
hi
-
KiChjang
!hi @ boomshroom
-
rustbot
boomshroom: Hello. ^.^
-
boomshroom
Is it possible to generate a binary for a custom target? I'm doing some OSDeving and it seems like I can get everything working if I pretend like I'm x86_64-unknown-linux-gnu with some linker flags, but the moment I add a custom target, "error: cannot produce bin..."
-
boomshroom
I know Phil-opp got around this by building a static library and linking afterwords, but I like not using a Makefile and trying what I can within the languages native environment.
-
boomshroom
Does anyone have any ideas, or do I just have to resort to a dedicated linking step or pretending to be linux?
-
» albel727 has none, unfortunately
-
albel727
maybe #rust-embedded or #redox guys know better
-
albel727
but I wouldn't expect immediate answer, to say the least
-
boomshroom
albel727: Thank you for your response. They probably would.
-
revoof
hi. i've got a (pretty much arbitrary
docs.rs/pgn-reader/0.4.0/pgn_reader…truct.Reader.html#impl-IntoIterator) iterator. how do i process the items in parallel? i've tried using rayon, but it looks like i can't just call into_par_iter() or par_iter()
-
mbrubeck
revoof: You could use `scope` to spawn off a bunch of parallel jobs
docs.rs/rayon/1.0.0/rayon/fn.scope.html
-
mbrubeck
as you loop over the iterator
-
albel727
-
albel727
which, it appears, doesn't do anything but converting things to Vec and using random access inside that, for most collections
doc.servo.org/src/rayon/collections/mod.rs.html#9-17
-
untitaker
is there a way in rust proc macros to enumerate all known types that implement a trait?
-
revoof
with the scope & spawn method, do i have to be careful to not spwan too many tasks?
-
revoof
the iterator is likely to create more data than can be collected in a vec
-
revoof
maybe i could spawn N tasks and wait until they are completed before spawning more
-
nox
-
neachdainn
Hey all. Is there a well known / standard crate for a fixed-size MPSC that removes the *oldest* element if the queue is full?
-
Arnavion
untitaker: No. Macros work on syntax. They have no type information. The type information does not even exist at the point macros are invoked
-
rovar
neachdainn: so a ring buffer? :)
-
» rovar wonders if someone has made a circular/ring buffer into a channel interface..
-
untitaker
Arnavion: I remember a weird hack that cbindgen uses: Invoking the compiler twice
-
untitaker
but nevermind, I figured out something even dumber to make it work
-
Arnavion
untitaker: Invoking the compiler from a proc macro is a good way to ensure nobody uses your proc macro
-
neachdainn
rovar: I imagine it would be backed by a ring buffer. I've written one that fits my bill, but if there's a "standard" one I would rather use that
-
centril
nox: looks fine to me..? modulo <<T as ToComputedValue>::Output as ToAnimatedValue>::Output which is not very readable
-
untitaker
Arnavion: I know
-
nox
centril: The where clauses on NumberOrPercentage are unfortunate.
-
rovar
neachdainn: there isn't a standard one.. most queues block when they're full, since losing data isn't always a desired feature
-
rovar
:)
-
nox
I could generate them but only with proc macro attributes which are not stable yet.
-
centril
nox: ah :(
-
remmy
Hm, is there any way to run just a single run-make test?
-
durka42
remmy: --test-args name_of_test
-
nox
centril: Do you think it would be reasonable to flow trait bounds from type aliases to data type definitions?
-
centril
nox: meaning that you add then as where bounds on the type def ?
-
centril
them*
-
centril
It depends on how intrusive it gets and if the bounds are natural for the data type itself
-
nox
centril: Meaning that my code would compile without lines 12-13.
-
nox
rustc knows which bounds are missing after all.
-
centril
nox: uhm... do you have the changed version so I can compare?
-
nox
-
centril
nox: so you are asking if those bounds are reasonable?
-
nox
No, I'm asking if it would be reasonable to make rustc just add them silently as part of the RFC for implied bounds.
-
centril
nox: uhm... implied bounds are afaik about eliding bounds on impls and fns... not type definitions themselves.
-
nox
Yes, so what could go wrong if it applied to type definitions too?
-
centril
nox: oh you want to amend the RFC?
-
nox
centril: Yeah.
-
centril
nox: I see - is the bound implied here tho?
-
nox
centril: What do you mean?
-
theobromine
so i am working on a service where some people will be building content in html, my system will parse the html, and turn it into some dynamic content. is there an excellent recommended html library for parsing in rust? maybe something like beautiful soup in python?
-
centril
nox: Number<Specified>: Phased<Phase> - implied?
-
j_ey
theobromine: html5ever
-
nox
centril: I don't understand what you are asking. It's not implied because rustc doesn't imply bounds.
-
theobromine
great thanks :)
-
centril
nox: but if rustc did, why should omitting that bound be legal?
-
nox
I want it to imply them.
-
nox
centril: Because it can't do anything without it.
-
nox
Its definition is type Number<Phase> = <SpecifiedNumber as Phased<Phase>>::Output;,
-
nox
so I want rustc to imply that SpecifiedNumber: Phased<Phase> when I use Number<Phase> with a generic Phase.
-
nox
I wrote it as Number<Specified>: Phased<Phase> because it's easier to write down by hand, if that's what you were asking about.
-
untitaker
is there a way to get the stringified type path from a TypeId?
-
centril
nox: no I got that you wanted SpecifiedNumber: Phased<Phase> to be implied... but letting this be implied would lead to pretty surprising code
-
nox
centril: That's what I want to know about.
-
talchas
untitaker: I don't think so
-
nox
centril: In general, trait bounds on type definitions are painful for that reason.
-
nox
centril: If implying them is ok on functions, why isn't it on structs and enums?
-
rustizer
where is a nightly release stored, is it on github? I was wondering where to find them and also what 'triggers' the making of the release, is it bors with some command from a human?
-
centril
nox: because then you have to look into each associated type to see if it carries a bound or not - so seeing if a type satisfies a bound becomes very hard
-
nox
centril: Ain't that the same for functions though?
-
nox
centril: Oh I guess it would be pretty bad for private fields in structs.
-
centril
nox: yeah, that =P
-
nox
centril: What about it only being implied for public fields?
-
centril
nox: I think that would encourage public fields too much
-
remmy
durka42: awesome, thanks.
-
nox
centril: Damn.
-
centril
nox: also, I think you need to draw the line somewhere so that you have some anchor that is easily checkable
-
centril
nox: anywho... time for food - laters =)
-
nox
See you.
-
Onix
Hello i want to make a Rust application with Tokio, do you any idea of application to learn Tokio ?
-
carllerche
Onix: chat application?
-
Onix
carllerche: i already did the chat application
-
carllerche
Onix: database?
-
Onix
Oh yeah good idea thanks !
-
albel727
is there some pre-made into_enum!(Type, Enum, Variant) macro, that would basically impl From<Type> for Enum { fn from(v: Type) -> Self { Enum::Variant(v) } } ?
-
albel727
I'm trying this new-fangled failure crate, and it appears to miss this boilerplate generation
-
albel727
which I of course could do myself, but if I can avoid copy-pasting that macro everywhere I want it, it would be nice.
-
jon
Is it possible to use hyper with tokio (not tokio_core)?
-
albel727
I heard they were going to switch to new tokio in the weeks coming. don't remember the actual dates.
-
carllerche
I'm working on being able to get tokio-core use the new tokio under the hood
-
carllerche
then it should just work
-
jon
ok, nice.
-
grants
I have a macro that looks like ` macro_rules! is_char_special { ($($chr:expr),+) => { ... } } `, so you call it like ` if is_char_special!('a', 'x', b') { .. } `
-
grants
If I wanted to make a macro that was " is_char_not_special ", how would I write it in terms of is_char_special? Specifically, I am having trouble passing the arg list from one macro to the other
-
durka42
grants: you can recreate the list as $(chr),+
-
durka42
oops $($chr),+
-
yoshuawuyts
o/ is there an equivalent of `npm link` for Cargo?
-
durka42
yoshuawuyts: what does `npm link` do?
-
yoshuawuyts
durka42: it symlinks a local project into the dependency directory
-
durka42
cargo doesn't have any concept of "globally" installing a dependency so I'm not sure there is a comparison
-
durka42
you can always just put a path in Cargo.toml though to depend on a local project
-
mbrubeck
-
durka42
not sure if I'm answering the question, the `npm link` man page is gibberish :)
-
yoshuawuyts
mbrubeck: perfect!
-
yoshuawuyts
mbrubeck: thank you; that's exactly what I was looking for :D -
-
yoshuawuyts
-
durka42
I think I like cargo's approach better, though it's sometimes incredibly difficult to convince cargo to actually replace the damn crate -- but it seems better to do it declaratively, rather than this one-off command that you forget you did...
-
neachdainn
I need something like `Vec::retain` but I want to be able to return a `Result` from the closure. What's my best bet?
-
stephaneyfx
neachdainn: Make the closure return `result.is_ok()`?
-
durka42
neachdainn: hmm what should the result be used for? stop on error?
-
neachdainn
I have a `Vec<Foo>`, I need to remove the `Foo` from the `Vec` if certain conditions are true, but I also need to be able to return any errors to the outside function
-
neachdainn
I'm thinking my best/only bet would be to iterate over the indices and do a swap remove?
-
durka42
yeah, I doubt there's going to be anything built in
-
stephaneyfx
neachdainn: The closure is FnMut so it could mutable borrow something to store errors which you can inspect after calling retain
-
chrisdotcode
hey killercup, is it possible to create a static binary with diesel as a dependency? I'm targeting musl, but my binary still seems to have dynamic deps. I assumed maybe it was the diesel codegenning or something?
-
stephaneyfx
*mutably
-
chrisdotcode
(or maybe I'm just doing something wrong with the building)
-
neachdainn
stephaneyfx: That's not ideal, but it's probably way less error prone than the swap remove way
-
eijebong
chrisdotcode: With sqlite you can IIRC, you need to add a feature to the sqlite dep though
-
mbrubeck
neachdainn: The body of `retain` is a tricky but short `for` loop:
doc.rust-lang.org/src/alloc/vec.rs.html#805-824
-
mbrubeck
neachdainn: You could do a similar loop explicitly in your code
-
chrisdotcode
eijebong: so it *is* diesel that is messing with the static linking, yes (and I'm not crazy)?
-
eijebong
chrisdotcode: Well I don't think our pg bindings nor our mysql ones support being statically linked
-
eijebong
-
neachdainn
mbrubeck: That's roughly what I was going to try. I don't know why I didn't think of just copying the code. Hahah
-
chrisdotcode
eijebong: ah, so if the pg bindings were able to be statically linked, diesel for postgres would be able to be statically linked?
-
eijebong
chrisdotcode: I think so, I'm not sure though
-
chrisdotcode
eijebong: is there something I could do to help out with that? my company wants to consider rust, but not being able to statically link diesel for postgres might be a show stopper unfortunately
-
eijebong
chrisdotcode: You can look at the postgres bindings, let me find you some links ;)
-
chrisdotcode
eijebong: <3
-
eijebong
sgrif/pq-sys #4 Actually you can do that already :D
-
eijebong
chrisdotcode: ^
-
chrisdotcode
eijebong: thanks! we'll try this out and let you know if it we can get it
-
Seeb
Hi, what is the difference between dependencies from crates.io and from local paths? Pulling num_bignum from crates.io makes the code 4 times faster than referencing the local copy (same code)
-
eijebong
chrisdotcode: Sure :) Always happy to help if you have any question (if I don't because I'm not there, you can also ask on our gitter channel, I'm pretty sure I'm the only one from the usual people answering questions that's monitoring IRC actively)
-
chrisdotcode
:)
-
Seeb
Oh well, now I found out that local dependencies are compiled incrementally while those from crates.io are not. CARGO_INCREMENTAL=0 gives the performace back, thanks anyway for listening ;)
-
boustrophedon
Seeb: if you notice that big a perf difference (and you're sure it's not you forgot to build with --release) you should file a bug for it on rustc
-
durka42
Seeb: are you talking compile time performance or runtime?
-
Seeb
durka42: Runtime, and I use cargo bench so it is compiled in release mode
-
durka42
definitely file a bug about that!
-
durka42
incremental shouldn't cause such a regression
-
boustrophedon
-
nox
-
centril
nox: so many versions =P
-
nox
centril: This reduces the boilerplate to `: NumberOrPercentagePhaser` and that derive.
-
centril
nox: =)
-
rustizer
hi, what would be the easiest way to convert a `Result<Vec<T>,E>` into a `Vec<Result<T,E>>`?
-
durka42
rustizer: usually it's the other way around...
-
rustizer
durka42: yeah, I know, but I am within a `flat_map` and I need to give it an iterator of results so that the final collect can short-circuit
-
durka42
what would the cases be? either it's Ok(vec) in which case the output is a Vec of all Oks, or it's Err in which case... what? a Vec of length 1 with the error in it?
-
rustizer
durka42: IOW, I need to call a function that returns `Result<...>` within `flat_map`
-
rustizer
durka42: right, an iterator with one error in it so that it works with `flat_map`
-
durka42
I guess I would just convert it manually then
-
durka42
match r { Ok(v) => v.into_iter().map(Result::Ok).collect(), Err(e) => vec![Err(e)] }
-
talchas
well, you don't need a vec of it, you just need an iterator
-
durka42
yeah that's true but good luck coming up with a single type...
-
rustizer
durka42: yeah, the `type soup` is a real pain with futures and iterators, I hope abstract data types or something similar comes up soon
-
rustizer
I guess the only way is manually like durka42 suggested
-
durka42
if you can't allocate memory or whatever, you can make a wrapper type around the original Result and impl Iterator on that
-
talchas
eval: let x: Result<i32, ()> = Err(()); x.into_iter().next()
-
eval
None
-
rustizer
durka42: I can allocate, that is no problem, I just really wish it would be easier to use results within iterators
-
durka42
you might be interested in {!crate fallible-iterator}
-
rustbot
fallible-iterator (0.1.4) - Fallible iterator traits ->
crates.io/crates/fallible-iterator <
docs.rs/fallible-iterator>
-
talchas
which is not /quite/ what you seem to want
-
durka42
it doesn't seem to have flat_map though
-
rustizer
talchas: that doesn't work because it ignores the error
-
talchas
yeah
-
rustizer
durka42: wow! that is a great crate, what I need, except it doesn't have `flat_map` as you said. Thank you for mentioning it though, I wish it had all the methods that iterators have.
-
durka42
yeah, I don't know how hard it would be to add
-
sfackler
shouldn't be too bad I don't think
-
kehtnok
When you're cross-compiling with -sys crate dependencies, your compilation toolchain should only need the proper library headers right? I realize this is less of a "Rust" question, but I'm viewing it through that lens, and there are a lot of smart people here :P
-
WindowsBunny
kehtnok: It depends on the -sys crate
-
kehtnok
openssl in this case
-
WindowsBunny
kehtnok: Crates that need to run bindgen at build time need the headers
-
kehtnok
which unfortunately seems to have different definitions on Android
-
kehtnok
WindowsBunny: ah I see, in order to codegen the FFI interface?
-
WindowsBunny
kehtnok: Crates which link to libraries the system/user is expected to provide, need the libraries themselves at link time
-
WindowsBunny
kehtnok: Yes, many -sys crates already come with the bindings written so they don't need bindgen at runtime, but some do
-
sfackler
kehtnok: in openssl's case it's to figure out the build time configuration of OpenSSL
-
WindowsBunny
kehtnok: Crates which build everything from source typically don't need anything other than a full cross compiling C toolchain
-
kehtnok
sfackler: Ah I see - would you have any specific recommendations for cross-compiling openSSL that doesn't involve building the platform specific library for the toolchain environment? japaric's cross project looks really promising but I don't know if we want to go full out if we don't need to
-
kehtnok
WindowsBunny: thank you for the detailed overview :D really appreciate it
-
sfackler
you could grab the openssl install off of your target system and stick it on your build system
-
sfackler
you'll need the headers + the libraries
-
kehtnok
sfackler: Ok so we'll need the full library as well? Not just the headers for the build time?
-
sfackler
eys
-
sfackler
*yes
-
kehtnok
is that part of the configuration setup stuff?
-
kehtnok
(just curioius)
-
sfackler
no, the linker needs the library to be there to link to it
-
kehtnok
at compile time?
-
sfackler
yep
-
kehtnok
Ah... huh. Always thought it'd just need the headers to resolve symbols but not actually load them or anything
-
myeisha
has anyone published a good writeup on how to make intrusive collections safe in the absence of allocators?
-
kehtnok
sfackler, WindowsBunny: thanks for the help!
-
myeisha
(i'm considering doing one myself, but if someone has done it already ...)
-
jpernst
TIL you can do <Foo<T>>::bar instead of Foo::<T>::bar
-
jpernst
that's such a huge lifesaver in a proc macro
-
durka42
jpernst: even in regular macros yeah
-
durka42
very well kept secret
-
durka42
they told us turbofish was the only way!
-
jpernst
i thought there was a section in the reference that describes fully qualified path syntax, but i can't even find it anymore
-
jpernst
thankfully i vaguely remembered it and decided to try, and it worked
-
lgspaw
i spend 2 hrs working out this lifetime stuff on something, and it turns out all it was is me forgetting to specify a lifetime on a return type :(
-
lgspaw
the compiler was right, but boy that was hard to track down
-
glandium
is there an exhaustive list of supported target_arch/target_os/etc.?
-
rkruppe-phone
glandium: Don't think so. Would be difficult too since it constantly expands
-
myeisha
-
glandium
rkruppe-phone: so, does cfg(target_arch="foo") work?
-
jpernst
lgspaw, yeah, nothing freezes the blood like "cannot determine appropriate lifetime for anonymous lifetime '_ due to conflicting requirements"
-
jpernst
but it feels great once you finally nail it
-
lgspaw
jpernst: that was EXACTLY the one i had!
-
glandium
myeisha: what's missing from there is that target_arch="x86" matches i586* and i686*
-
glandium
also, does target_arch="arm" include armv7?
-
lgspaw
i feel like with the anonymous lifetime stuff, you should get compiler warnings when you dont specify the lifetime
-
glandium
is there a target_arch value that works for across all powerpcs, 32 and 64 bits?
-
glandium
things like that
-
glandium
IOW, this seems way underspecified for something that's stable
-
dbkaplun
can someone explain to me what bors does on github?
-
myeisha
glandium: reference states for target_arch: "This value is closely related to the first element of the platform target triple, though it is not identical." - no help there :/
-
lgspaw
but i understand that the anonymous lifetime stuff is an ergonomics thing, and putting warnings would ruin that
-
dbkaplun
does travis do the same thing as bors?
-
jpernst
yeah, anonymous lifetimes are great until they're not
-
jpernst
but thankfully, the more you work with it, you develop an instinct for where the problem probably is
-
lgspaw
yeah
-
lgspaw
that makes sense
-
rkruppe
glandium: cfg(target_arch="foo"), literally, does not work. but theoretically might work in the future if someone creates an architecture with that name and rust gains support for it :)
-
rkruppe
glandium: ("does not work" = is never enabled, you won't get an error)
-
glandium
rkruppe: so you can make typos, and get screwed over. great
-
rkruppe
glandium: This is nothing target_arch specific, it applies to all cfgs that "have values", including e.g. cargo features
-
rkruppe
And we wouldn't want to error on it anyway since that would make adding conditional support for a new target architecture break compatibility with older rust versions that don't know that arch
-
glandium
so, rustc apparently takes target_arch from Session.target.target.arch, however that's filled from
-
rkruppe
Ultimately it comes from the target spec (built in or JSON)
-
rkruppe
So you wouldn't even need to modify rustc to add target_arch="foo", just write a target spec in JSON :)
-
glandium
-
glandium
and that only outputs for the current target. Is there anything to print out everything the compiler supports? iterating that with the output from -print target-list?
-
rkruppe
glandium: If you really wanted to. I don't know why you want an _exhaustive_ list though. Since it can expand at any time, and users can add new ones with custom target specs.
-
glandium
rkruppe: because I want to figure out the answers to the questions I asked earlier, and more
-
rkruppe
glandium: If you have a question about a specific target (like armv7), then try for that specific target.
-
glandium
so, for example, target_arch="arm" does include thumb* arm-* armv4* armv5* armv7*
-
glandium
and it would seem there's no way to distinguish whether you're building for arm or thumb
-
glandium
huh? the llvm target for asmjs-unknown-emscripten and wasm32-unknown-emscripten are both asmjs-unknown-emstripten
-
glandium
but one is arch=asmjs and the other arch=wasm32
-
dbkaplun
can someone explain to me what bors does on github? does bors do the same thing as travis (i.e. CI)?
-
rkruppe
dbkaplun: bors creates a merge commit and instructs CI (travis and appveyor) to run it, observes the result and pushes the merge commit to master if CI passes.
-
rkruppe
this is different from the regular travis CI run in that it tests the code that will end up in master, not the current state of your branch (which may be behind master)
-
boxdot
Hi. I am trying to find any rules about alignment of struct X { data: [u8; SIZE] }. Would it be portable and not UB to cast from some position in a Vec<u8> to X?
-
mbrubeck
The `bors` account is currently run by a program called `homu` which is a successor to the original `bors` program
github.com/servo/homu
-
panicbit
boxdot: No
-
talchas
boxdot: that is unspecified
-
rkruppe
boxdot: You need to nail down the layout of X to be able to do that, though not for alignment
-
rkruppe
(although I guess technically we've never specified that repr(Rust) structs have the sensible alignment?)
-
boxdot
But X{ data: u8 } is 1-byte aligned, right?
-
talchas
in practice afaik there's no platform that would break for that particular struct
-
panicbit
Define portalbe?
-
panicbit
portable*
-
talchas
boxdot: on any sensible platform, yes
-
rkruppe
boxdot: same answer: repr(C) yeah sure, but without that it's not technically specified -- and layout is unspecified too so you're not allowed to pull such tricks regardless of alignment
-
boxdot
panicbit: plattforms used in practice? not sure, though.
-
talchas
(and repr(Rust) in particular is unlikely to put up with platforms being dumb about that)
-
boxdot
ok, sounds like a bad idea. thanks!
-
panicbit
Yeah, better avoid transmuting stuff
-
dbkaplun
doesn't travis do merge commits?
-
rkruppe
dbkaplun: No
-
dbkaplun
there's two checks PR and push, is PR different?
-
rkruppe
Probably because strict adherence to that would effectively serialize CI runs
-
rkruppe
PR is presumably what travis runs on every PR automatically. while push should be bors
-
dbkaplun
i was pretty sure the Travis PR check does a shadow merge
-
boxdot
If I understand correctly, it also implies that std::slice::from_raw_parts::<T> is very dangerous due to unspecified layout of T?
-
boxdot
s/layout/alignment.
-
dbkaplun
Travis does a shadow merge for PR, and tests the commit as-is for push
-
dbkaplun
is that different than bors?
-
rkruppe
boxdot: Nah the layout of slices is specified and if you have valid Ts behind the pointer, everything's fine
-
glandium
warning: spurious network error (2 tries remaining): curl error:
-
glandium
; class=Net (12)
-
rkruppe
dbkaplun: I don't follow. But I also never looked that deeply into the CI setup
-
glandium
that's ... not really helpful
-
dbkaplun
i guess i'm having a tough time understanding what bors does. does it make a merge commit and test that? or something else?
-
glandium
so... that meant "no ca-certificates.crt"
-
durka42
dbkaplun: bors merges PRs into a running branch called "auto"
-
durka42
then from there to master
-
durka42
if I understand correctly
-
durka42
this is more reliable than testing a PR branch in isolation
-
dbkaplun
right, ok
-
mbrubeck
and what gets pushed to master is always a fast-forward to exactly the commit that passed tests
-
dbkaplun
travis does that, if i understand correctly
-
durka42
-
dbkaplun
mbrubeck: yeah
-
durka42
are you sure? I think travis could be green for PRs #1 and #2 but if you merge both they might conflict
-
dbkaplun
travis has two checks, one called push (for the branch) and one called PR (that makes a shadow merge which is fast-forwarded to on merge)
-
mbrubeck
It won't automatically do a new merge and re-run tests if new commits are pushed to master, though, AFAIK
-
mbrubeck
which leads to the situation durka42 mentions
-
dbkaplun
oh really? that's a bug then
-
rkruppe
No, it's probably intentional
-
mbrubeck
The downside to the homu approach is that everything gets serialized in a queue
-
dbkaplun
why would that be intentional?
-
rkruppe
Since re-running CI every time master changes would burn A LOT of resources
-
mbrubeck
since it's impossible to test multiple PRs in parallel under homu's model
-
rkruppe
and also ^
-
rkruppe
many projects don't care for that
-
mbrubeck
Travis runs things eagerly and in parallel
-
mbrubeck
homu runs things in serial, but waits until they are approved
-
dbkaplun
you're right, travis doesn't rerun on target branch update
-
dbkaplun
-
dbkaplun
that's an old issue though
-
mbrubeck
If it did, then having n commits open at once would lead to O(n^2) builds when they all merge
-
dbkaplun
how does homu avoid that?
-
mbrubeck
All approved PRs go into a queue
-
mbrubeck
it takes the first PR in the queue, creates a merge, and runs tests on that
-
mbrubeck
if the tests succeed, it fast-forwards master to that merge.
-
mbrubeck
then repeat with the next thing in the queue.
-
mbrubeck
-
dbkaplun
so homu is only run on approve
-
mbrubeck
yeah
-
rkruppe
aside: jesus the queue is long these days
-
mbrubeck
There's an even longer than usual backlog right now because of problems with bors's GitHub permissions last night.
-
rkruppe
It's been pretty bad for a while now. I had a PR approved a week ago and there's still twenty things ahead of it
-
centril
things you find while searching for "rust lazy rose tree":
rosesandrustblogger.blogspot.se/2017
-
boxdot
How actually the impl. of does `slice::from_raw_parts` work? The impl. is `mem::transmute(Repr { data: p, len: len })`, so it transmutes a value type into &[T], which behaves like a ref. It needs some black magic compiler support, or not?
-
cls
centril: what rust needs is more south african gins
-
mbrubeck
boxdot: It depends on knowledge that `&[T]` is a fat pointer that is represented in memory as `(ptr, len)`
-
centril
cls: #[repr(C)] struct Repr<T> { pub data: *const T, pub len: usize, }
-
myeisha
not so much black compiler magic as library voodoo then ;>
-
rkruppe
boxdot: The only magic is knowing how a &[T] pointer is laid out internally (which is unspecified, but libstd doesn't care)
-
mbrubeck
boxdot: You're right that this is coupled to the compiler. Outside of the standard library, it's not safe to rely on this, because it might change in the future.
-
mbrubeck
boxdot: but libstd is distributed with the compiler, so it can rely on knowledge of compiler internals.
-
boxdot
This is interesting. Thanks.
-
centril
I meant to cc boxdot =P
-
boxdot
I am trying to build a wrapper type around &u8 (or *u8), which I would like to return as a ref (e.g. because of the Index trait), but I can't do something similar: transmute value to ref.
-
rkruppe
boxdot: It doesn't sound like this is necessary or a good idea at all. Can you give more detail?
-
boxdot
rkruppe: I have a Vec<u8>, which I would like to enrich with some methods e.g. with getters and setters at specific indexes that operate just on bytes.
-
boxdot
rkruppe: For that, I would need to do something like Vec<u8> -> Vec<Wrapper>.
-
rkruppe
boxdot: Vec::from_raw_parts
-
mbrubeck
That's if `Wrapper` has the same layout as `u8`
-
rkruppe
boxdot: However note that you need repr(transparent) or repr(C) for Wrapper and u8 to be interchangeable
-
jschievink
is anyone else having issues with the newest stable where Travis times out when caching build artifacts?
-
boxdot
rkruppe: But how to I ensure that Wrapper has the same layout?
-
boxdot
rkruppe: Ah, you where faster.
-
mbrubeck
if `Wrapper` actually contains an `&u8` then you'd instead probably want a function from &Vec<u8> -> Wrapper
-
centril
hmm... would: struct Rose<V> { root: V, forest: impl Iterator<Item = Rose<V>>, } ever be a thing? I can do: struct Rose<V> { root: V, forest: Box<Iterator<Item = Rose<V>>> } but dynamic dispatch is meh
-
boxdot
mbrubeck: This one would not be compatible with the Index trait.
-
mbrubeck
right
-
myeisha
centril: that would be ... interesting
-
centril
myeisha: yeah =P
-
myeisha
also impossible? ;)
-
centril
myeisha: why?
-
myeisha
if not all impls for the impl Iterator are the same you need dynamic dispatch
-
boxdot
mbrubeck: Which is ok. — There is another problem, which is more severe. Wrapper needs to have a lifetime parameter to make the operations safe, but at the same i would like to parametrize also Wrapper. And this is not possible since Container<Wrapper> on creation is also parametrized by this lifetime.
-
myeisha
and if they are you can add the impl type to the generic params
-
centril
myeisha: oh yes, you get a single Iterator type for all Rose<V>s
-
centril
so it doesn't work - bummer
-
myeisha
it might work for nonrecursive things
-
centril
myeisha: the point is the recursion tho =)
-
centril
If I add a parameter I as in: struct Rose<V, I> { root: V, forest: I } that just leads to other troubles with overflowing requirements eval
-
boxdot
rkruppe: transparent seems like a very cool feature. did not know about it.
-
myeisha
centril: yeah, that's what tou get with structures that can grow forever
-
lucasem
I'm having a hard time regarding generators and borrowing (msg in playground):
play.rust-lang.org/?gist=e78195c663…cd0212c6865555e134f&version=nightly
-
centril
-
glandium
is there a way to make rustfmt indent stuff within macros?
-
glandium
(macro calls)
-
centril
(might be premature since I haven't fixed everything yet =P)
-
talchas
lucasem: well, outside of unsafe code
-
centril
myeisha: now you can still use the boxing, but the Strategy gets to decide this
-
talchas
you could manually store the next index
-
lucasem
talchas: then I'd have to store the whole iterator in memory as a slice or something
-
talchas
yeah
-
talchas
there's a reason they want to make this possible
-
lucasem
talchas: how could I do this unsafely? I don't see why it's bad that a borrow during yield happening when the generator owns the value
-
talchas
lucasem: generators can be moved, and that would invalidate any pointers
-
lucasem
talchas: ah interesting
-
talchas
(but if it's already a pointer and you're just reborrowing, then it's safe, just rustc doesn't know it)
-
talchas
you'd unsafely turn it into a 'static reference
-
lucasem
Yeah I'd rather work nicely within the lifetime system.
-
lucasem
I'll see if I can get Rc to work appropriately
-
talchas
you'd need the iterator to hold an Rc rather than a reference
-
talchas
which is possible if you're writing the underlying iterator yourself, but none of the builtin collections have an option to do that
-
lucasem
I initally tried just using an iterator, but ran into issues with lifetimes of borrowed values. So I figured I just want the iterator to own the value. After much trial and error, I figured generators would be my solution. This borrow issue in making me think otherwise..
-
talchas
probably not, no
-
lucasem
haha thanks. Time to *reiterate*
-
dbkaplun
is everyone in the business writing rust on nightly?
-
sarnold
no
-
mbrubeck
All the Rust code in Firefox is built with the stable toolchain
-
dbkaplun
well, rust was purpose-built by mozilla for usage in firefox. so that helps i guess
-
mbrubeck
Servo still uses a number of nightly features, but we're gradually moving away from them
-
mbrubeck
-
phaazon
anyone knows why Path doesn’t implement Display for &'a Path?
-
phaazon
and why we must use the Path::display method instead?
-
sarnold
could a properly placed * save the day?
-
WindowsBunny
phaazon: Because it might contain non-unicode
-
phaazon
I don’t get it
-
WindowsBunny
phaazon: Because implementing Display directly would allow ToStrong
-
WindowsBunny
ToString rather
-
mbrubeck
phaazon: We don't want people using `path.to_string()` and not realize that it's potentially lossy/inaccurate
-
WindowsBunny
which doesn't make sense for a conversion that could *fail*
-
lgspaw
when matching on a struct, is there a way to use ignore wildcard without specifying members of struct?
-
mbrubeck
lgspaw: `MyStruct { .. }`
-
lgspaw
e.g. currently need to do match x { Something { x:_, y:_ } => ... }
-
phaazon
ok!
-
phaazon
seems legit :)
-
lgspaw
ahhhhh
-
lgspaw
mbrubeck: thanks :)
-
phaazon
thanks for the explanation <3
-
lgspaw
kept trying MyStruct _
-
lgspaw
is match x.unwrap() { vs let test = x.unwrap(); match test { another example of the lexical scoping issue?
-
lgspaw
(one compiles, one doesnt)
-
lgspaw
(or maybe i imagined it)
-
Onix
How do you make a raw pointer to an array ?
-
phaazon
*const [T]
-
WindowsBunny
Onix: Do you need a raw pointer for FFI purposes?
-
Onix
Just like that ? You can put the length of the array to ?
-
mbrubeck
Onix: let array = [1,2,3]; let ptr = &array as *const [i32; 3];
-
Onix
WindowsBunny: No not for FFR purposes
-
Onix
FI*
-
Onix
FF*
-
Onix
too*
-
Onix
FFI*
-
ngc0202
is anyone familiar with the socket2 crate?
-
ngc0202
-
Onix
Ok thanks !
-
ngc0202
says can convert to and from std::net::SocketAddr, but I can only see functions to convert from it not to
-
WindowsBunny
*const [T] will be a fat pointer while *const [T; N] will be a thin pointer
-
WindowsBunny
ngc0202: Don't forget the blanket impl between Into and From
-
ngc0202
there's only impl From<SocketAddr> for SockAddr
-
sfackler
the `impl From<SocketAddr> for SockAddr` takes care of the other direction
-
ngc0202
no
-
ngc0202
that's still only one direction
-
WindowsBunny
hmmmmmmmmmmm
-
lgspaw
is there a shorthand for hash_map.or_insert(x) to only insert x if it is Some and doesnt exist?
-
mikeyhew
what's the recommended way to do argument parsing?
-
WindowsBunny
mikeyhew: like the stuff that clap does?
-
Onix
Something like that is possible ? let pointer = 0xb8000 as *mut [80 * 24; u8] ?
-
WindowsBunny
Onix: *mut [u8; 80 * 24] but yes
-
mikeyhew
WindowsBunny: that looks like what I'm looking for, thanks
-
Onix
What is the difference between the fat and thin pointer ? In the fat pointer you don't know when the array end ?
-
WindowsBunny
the fat pointer keeps track of the size at runtime
-
WindowsBunny
which makes it fat, because it is twice as large as a normal pointer
-
WindowsBunny
the thin pointer knows the size at compile time and therefore doesn't need to keep track of it at runtime
-
Onix
Twice as large as a normal pointer ?
-
WindowsBunny
yep
-
Onix
What do you mean by that ?
-
mbrubeck
eval: std::mem::size_of<*const u8>()
-
eval
error: expected expression, found keyword `const`
-
eval
--> src/main.rs:3:28
-
eval
-
mbrubeck
eval: std::mem::size_of::<*const u8>()
-
eval
8
-
mbrubeck
eval: std::mem::size_of::<*const [u8]>()
-
eval
16
-
ngc0202
oh sfackler you're listed as an owner of socket2?
-
Onix
So that is the size of the pointer ?
-
ngc0202
sfackler: so I need to go in the direction of SockAddr -> SocketAddr
-
ngc0202
the From impl only gives SocketAddr -> SockAddr
-
ngc0202
so is the documentation wrong or is there a way hidden somewhere?