• tiby312
    thx talchas
  • sezna
    is it possible to read a file in parallel with rayon?
  • sezna
    or is that an inherent race condition?
  • albel727
    it depends. some oses have methods to read files without altering seek position. but you're not likely to use something that would use them internally.
  • insaneinside
    sezna, POSIX does indeed allow you to have multiple file descriptors (handles) for the same file -- so I don't think such a thing is necessarily verboten
  • gchristensen
    but it can certainly lead to unexpected behavior
  • sezna
    Well, I'm trying to read a 400mb file and am concerned about performance. Would using a BufReader to read the lines one by one and then turn it into a par iter be okay?
  • keeper
    sezna: Have you looked at memory mapped files?
  • gchristensen
    you're going to be blocked on disk IO, sezna, not CPU time. that'd be fine
  • sezna
    keeper nope, not familiar with that
  • sezna
    gchristensen thanks
  • sarnold
    sezna: depending upon your access patterns, multiple read heads in a file may be drastically drastically worse
  • sarnold
    sezna: spinning metal drives are great at "read these several megabytes in a row"
  • sarnold
    if you ask for megabyte 0, 100, 1, 101, 2, 102, etc., the heads will be bouncing back and forth and quite possibly going way slower than 1, 2, 3, ...
  • sarnold
    if your underlying storage doesn't have penalties for random access (ssd, nvme), or actually has multiple drives backing the file (RAID / zfs / btrfs etc) then you might be able to do better than just a single 'read head' in the file
  • garagedragon
    Would it be at all effective to have a seperate thread do the disk IO serially and put all the contents in a spmc queue?
  • garagedragon
    Or would you be just reinventing memory mapped files at that point?
  • insaneinside
    emilio: rust-lang-nursery.github.io/rust-bindgen/whitelisting.html mentions whitelisting _rules_, which (to me) suggests the possibility of simply whitelisting a common prefix used by the API I'm generating bindings for. But I only see `whitelist_<noun>`, for whitelisting _specific_ things!
  • kehtnok
    well no matter what you're gonna be stuck on disk io, so it depends on the use case. mmaps are nice since they don't page in until you access specific pages of the file
  • sarnold
    garagedragon: I suspect at that point you've made it worse, since you'll be copying data from the thread to memory once, and then sending that memory through a channel primitive which _probably_ (no guarantees) re-copies the data, maybe even with new allocations too..
  • garagedragon
    sarnold: I imagine there's some way to work around that, like sending a Box or Arc or something, but it was just an offhand suggestion. For all I know it's not workable.
  • sarnold
    garagedragon: doing disk IO in threadpools is a time honoured tradition to try to emulate async IO APIs :) so it's definitely got uses
  • garagedragon
    (is Box Send? I can't find it in the manual...)
  • talchas
    yes, it's Send/Sync if T is
  • garagedragon
    ah
  • talchas
    unfortunately the Send/Sync impl is on Unique so you don't see it in the docs
  • Jtremback-M
  • Jtremback-M
    the infamous "cannot move out of borrowed content"
  • tiby312
    how to i opt out of doc compiling example code?
  • insaneinside
    tiby312: ```rust,ignore
  • insaneinside
    or just ```ignore
  • tiby312
    thx
  • KiChjang
    Jtremback-M: uh oh, looks like lines() takes a self
  • insaneinside
    but the latter says that your example is in the "ignore" language :|
  • Jtremback-M
    KiChjang: any suggestions?
  • talchas
    (&mut self.stream).lines()
  • KiChjang
    huh, does that work?
  • KiChjang
    talchas: WTF!!!!
  • KiChjang
    what magic is this?!?!?!
  • talchas
    impl<'a, T: ?Sized + Read> Read for &'a mut T
  • talchas
    much like iter
  • Jtremback-M
    huh
  • talchas
    there may actually be a .by_ref() too like iter
  • talchas
    yeah, self.stream.by_ref().lines()
  • garagedragon
    talchas: ah, thanks, the Unique thing was what I was missing.
  • Jtremback-M
    cannot borrow immutable field `self.stream` as mutable
  • KiChjang
    Jtremback-M: yeah, just change your self param to take in &mut self instead
  • Jtremback-M
    oh yea nvm
  • KiChjang
    Jtremback-M: the .lines() call would advance the stream, so it either has to be mutable, or take ownership
  • Jtremback-M
    i prefer by_ref
  • Jtremback-M
    `(&mut self.stream).lines()` seems hard to read
  • KiChjang
    that's fine, but .by_ref() still requires your stream to be mutable
  • Jtremback-M
    yea
  • KiChjang
    the most dreaded error of all time is "cannot infer an appropriate lifetime due to conflicting requirements"
  • KiChjang
    but it's "fixed" in nightly, right now it says something like "lifetime annotations required"
  • Jtremback-M
    KiChjang: i got that one once
  • Jtremback-M
    it was like 2 pages long
  • Jtremback-M
    aside from my ownership woes, does this look like a good way to do things:
  • » Jtremback-M sent a long message: Jtremback-M_2017-12-14_00:42:40.txt <matrix.org/_matrix/media/v1/downloa…matrix.org/UWSzXiNAapOSfzCEOxIDYfHy>
  • Jtremback-M
    just the whole thing with the loop and the concatenation
  • sezna
    Im trying to use rayon and im getting help: the trait `std::iter::Iterator` is not implemented for `rayon::slice::Iter<'_, &str>`
  • KiChjang
    Jtremback-M: the &line? thing looks magical to me
  • sezna
    is this because there is no send and sync for &str? I tried with String too
  • KiChjang
    Jtremback-M: also, why not ret.extend_from_slice or ret.push instead?
  • Jtremback-M
    is that better than +?
  • emilio
    insaneinside: you can whitelist using regexes
  • emilio
    insaneinside: `whitelist_type("your_api_.*")`, etc
  • KiChjang
    Jtremback-M: i don't recall the exact semantics, but i think + turns your &str into a String
  • KiChjang
    Jtremback-M: whereas ret.extend_from_slice and ret.push still does, but allocates the characters directly into the String, instead of creating another Vec and concatenating afterwards
  • Jtremback-M
    oh nice
  • garagedragon
    sezna: rayon::slice::Iter is a ParallelIterator, so I tihnk you have to call methods on it because a for-loop can't be hoisted to run in paralllel
  • insaneinside
    emilio: soooo it looks like `.generate_comments(true)` does all of diddly-squat. Is this true?
  • emilio
    insaneinside: it should
  • » KiChjang is trying to google diddly-squat
  • Jtremback-M
    KiChjang: it says that String doesn't have extend_from_slice
  • KiChjang
    Jtremback-M: right, because i've mixed it up, only vec has it
  • KiChjang
    String has .push_str instead
  • insaneinside
    emilio: well the only comment I'm seeing is `/* automatically generated by rust-bindgen */`, and I've fgrep'd for both "//" and "/*"
  • emilio
    insaneinside: it only generates doc comments, `/** */` and similar
  • insaneinside
    emilio: ...so? `fgrep '/*' bindings.rs` would match that kind of pattern
  • kristof
    I cna't believe i'm asking this
  • kristof
    if I have an Option<T>... how do I unwrap and call methods on &T?
  • albel727
    as_ref()
  • albel727
    as_ref().unwrap() even
  • kristof
    ohhhh, that's the method
  • kristof
    I was trying unwrap_ref
  • kristof
    dope
  • albel727
    also note as_mut()
  • insaneinside
    emilio: if you meant that it only _includes_ comments from the source that match that style, then yes those definitely exist github.com/OpenKinect/libfreenect/b…ter/include/libfreenect.h#L212-L220
  • Mako
    I added regex syntax to this scripting language I threw together github.com/malleusinferni/canary/blob/master/src/pattern/parse.rs
  • Mako
    ...And now I find out the regex crate provides no facility for compiling a pattern from your own AST
  • Mako
    Hmmm
  • cbreeden
    Mako: why don't you just use a Regex token which is nothing more than a string slice and pass it to regex?
  • Mako
    cbreeden: I want to support splicing local and global variables into the regex
  • cbreeden
    that's unfortunate
  • Mako
    So even if I do that, I have to parse first, then expand variables, then reduce it to a string using the regex crate's syntax
  • cbreeden
    right (also, I don't know of another way)
  • cbreeden
    though I think regex has syntax for comments which you could use as a easy escape to just search & replace?
  • Disconsented
    This is going to sound silly because it is: I want to have a program that acts as a relay for two others, the catch is that it wont open a new connection. My question is, how do I efficently pass data between the two streams? I can probably use a hashmap to achieve this but is there a better way?
  • sarnold
    hey Disconsented :)
  • Disconsented
    ello
  • Disconsented
    Releated question :P
  • cbreeden
    not inline comments though (which is probably desired)
  • cbreeden
    Disconsented: i'm curious if this would work crates.io/crates/ipc-channel
  • KiChjang
    not quite on windows
  • cbreeden
    KiChjang: well there is that PR that has been sitting there _since forever_
  • Disconsented
    I had forgotten about channels, reading time!
  • sarnold
    Disconsented: I think I'd just start up a bunch of threads and read from one socket in a busy loop and push to the other socket.. with a few hundred connections, I don't think the thread overhead will be too bad, and it's way easier imho than getting tokio up and running for this
  • kristof
    ok
  • kristof
    has anyone here ever, ever in their ever lives, defined a type in any language with both public and private fields and not regretted it
  • cbreeden
    me
  • kristof
    what was the usecase
  • cbreeden
    one field was a PhantomData
  • kristof
    that was the private one?
  • sarnold
    does that even count? :)
  • kristof
    lol
  • kristof
    yeah
  • cbreeden
    :x
  • kristof
    just barely
  • kristof
    it's not really private so much as making the compiler happy
  • cbreeden
    kristof: I have an Array<'buf, T> { buffer: &'buf [u8], pub length: usize, phantom: PhantomData<T> } type for instance. Making &'buf [u8] public didn't really make sense since I was it is supposed to act like a lazily parsed &[T]
  • kristof
    cbreeden: hm, I see, but..
  • kristof
    I mean length didn't have to be pub :P Also I feel like if I wrote length += 1 somewhere in client code that would break your logic
  • » cbreeden quietly removes pub from length
  • cbreeden
    kristof: i don't know what you are talking about
  • sarnold
    lol
  • Lokathor
    so how does the simd crate work when the processor it's compiled for doesn't support that
  • Lokathor
    does it fail to compile or just virtualize the operation to get the same result slower?
  • gchristensen
    it'd probably compile fine but fail to execute
  • YungMoonHodler
    whats the recommended way to make a multiline/multirecord nom parser from a parser that parses 1 record in 1 line?
  • YungMoonHodler
    separated_list!(p, "\n") ?
  • YungMoonHodler
    but how to make it work with \r\n too?
  • keeper
    I'd recommend using ws! somewhere in there.
  • YungMoonHodler
    keeper: i tried but it doesnt work, it includes '\n' in the record
  • keeper
    You might try asking in #nom.
  • robbym
    Was there a work around for the lack of sealed traits?
  • robbym
    Is there *
  • robbym
    Or just a way to prevent someone from implementing a trait
  • Kingsquee
    I forget, how are you supposed to do this again? play.rust-lang.org/?gist=592ecf5ec5…f083fe2d99e3421dba1b&version=stable
  • Mutabah
    Kingsquee: You need to use a trait e.g. num::Zero to get the zero value
  • Kingsquee
    Mutabah, yeah, but I want arbitrary values
  • Mutabah
    Nothing prevents someone implementing `BaseType` for Vec, which doesn't have an integer literal representation
  • Kingsquee
    so conceptually some kind of from()
  • robbym_
    System crashed. Did someone answer th sealed trait thing?
  • robbym_
    Oh. My other nick is still logged on...
  • robbym_
    And left
  • cbreeden
    robbym: no, but i remember someone mentioning a trick about requiring a trait to implement a private trait?
  • keeper
  • cbreeden
    yeah that's the thread i had in mind
  • robbym
    Yeah I saw that. Someone suggested using `unsafe`, but that doesn't really prevent someone from implementing some trait.
  • Kingsquee
    so I guess the only way to do this would be to make the basetypes wrappers that implement from
  • robbym
    cbreeden: I remember something like that as well but I can't remember what exactly
  • keeper
    There are a few workarounds spread throughout the thread.
  • robbym
    Oh, I'll dig deeper then
  • cbreeden
  • robbym
    Thats the one
  • cbreeden
    > pub(self) fn private_method_that_cannot_be_implemented_outside_of_this_module_making_the_trait_sealed();
  • robbym
    lol
  • Kingsquee
    something along the lines of SignedInteger<N8>::from(value: i8) I guess
  • robbym
    Oh interesting.
  • robbym
    Seems like an accident though
  • mr_pants
    does anyone here know an easy way to randomly generate an integer in a given range?
  • robbym
    (time * bignumber) % range
  • robbym
    ?
  • robbym
    Easy, but not too random.
  • mr_pants
    yeah i meant more randomized
  • mr_pants
    like a crate or something that has this functionality
  • robbym
    Does the rand crate not provide this?
  • mr_pants
    i wasnt able to find random integer in range functionality there
  • cbreeden
    rand can definitely do this
  • mr_pants
    do you know how?
  • cbreeden
  • cbreeden
    because i've done this :P
  • insaneinside
    From doc.rust-lang.org/std/ffi/struct.CStr.html: "This dynamically sized type is only safely constructed via a borrowed version of an instance of CString." Yet in the first example, we create a `&CStr` from a `*const c_char`!
  • insaneinside
    Is it just me, or is that just a *little* bit contradictory?
  • SpaceManiac
    the one says "only safely constructed", the other is an unsafe construction
  • insaneinside
    ... safe and "safe"
  • keeper
    insaneinside: I'd say using CStr directly is most common when building a string from a pointer allocated in C-land.
  • insaneinside
    which is exactly what I'm doing, FWIW
  • cbreeden
    it makes sense for this to require unsafe to me
  • insaneinside
    it does. But my mind was translating "safe" to "sane"
  • robbym
    Woah. Rust in visual studio
  • Woew
    More non-rust bugs to care about!
  • Woew
    robbym, does this mean that clang support will come back?
  • cbreeden
    Woew: in VS 2017 preview there is experimental support
  • cbreeden
    at least said a checkbox during installation
  • robbym
    gonna boot up windows to check it out :D
  • cbreeden
    i had installation problems on my laptop :( I should try again tonight
  • Woew
    cbreeden, yeah, it sucks, as it doesn't use llvm entirely, and it is being dropped (hopefully in favor of full llvm capability)
  • Kingsquee
    what I'm trying to do is use typenum to derive the kind of integer a struct will use as a backing type, and then create a constructor for that struct
  • Kingsquee
    so like Foo<U1, U7> would have a u8 backing type
  • Kingsquee
    so with some trait shenanigans that works nicely
  • Kingsquee
    but making 'new(value)' is kind of baffling me
  • Kingsquee
    since I'm once again assuming the parameter will work because it'd make sense only from what I've implemented it on
  • Kingsquee
    which isn't how traits work
  • Kingsquee
    so I guess I'd have to explicitly have something like Foo<U1, U7, u8> for it to make sense of this
  • Kingsquee
    which is a bit unfortunate
  • soc
    hi, I'm trying to call msdn.microsoft.com/en-us/library/bb762188.aspx from rust
  • soc
  • soc
    but I'm unsure how to retrieve the right KnownFolderIds that are described here: msdn.microsoft.com/en-us/library/dd378457.aspx
  • soc
    ani deas?
  • soc
    should I just hardcode the GUID values?
  • Arnavion
  • soc
    oh, cool, thanks, didn't found this
  • Arnavion
    You just had to put the name of the FOLDERID in the seach box :)
  • soc
    true, didn't think of searching it that way
  • soc
    Arnavion: I'm not too familiar with the Win Api ... which args would I use from rust to call a method like retep998.github.io/doc/shell32/fn.SHGetKnownFolderPath.html ?
  • soc
    dwFlags can be zero, but what about hToken and pszPath?
  • WindowsBunny
    >If this parameter is NULL, which is the most common usage, the function requests the known folder for the current user.
  • Arnavion
    Read the MSDN article
  • soc
    how do I know how large the buffer needs to be for the path?
  • WindowsBunny
    std::ptr::null_mut() gives you NULL
  • WindowsBunny
    soc: 32768 WCHAR will hold all possible paths
  • Arnavion
    You don't give it a buffer
  • Arnavion
    It's a PWSTR*
  • Arnavion
    It gives you a buffer
  • Arnavion
    Apart from the type you can also see it's SAL-annotated as _Out_
  • WindowsBunny
    but in this case it isn't asking for a pointer to your buffer, it is asking for a pointer to a pointer
  • WindowsBunny
    so it can mutate your pointer to point to its own buffer, which you have to remember to free with CoTaskMemFree later
  • soc
    wtf ... thanks
  • soc
    so I can pass a mut pointer to a null pointer, and the call will mutate that?
  • Arnavion
    Yes
  • Arnavion
    The equivalent of WCHAR* buffer = nullptr; foo(&buffer); from C++
  • soc
    I' m seriously considering to spawn a process, run powershell in it, and call the .NET framework method that does the same ...
  • dobkeratops
    has auto-borrow been discussed for operators and even function parameters, given that receivers can do it (i.e. foo.bar() works for bar(&self) .. it would make sense if a+b worked for add(&self,rhs:&Self)? ... given the specificty of naming (no overloads) would that avoid clashes
  • dobkeratops
    might sound minor but coming from c++ reference behaviour (and 'pass-by-reference') in many other languages, having to write (and read) a lot of & in the parameters does look a bit odd. i dont think autoborrow would be a problem because the expensive operation (.clone()) is explicitely marked and that is great. (you'd stick with the assumption that something syntactically light is cheap)
  • KiChjang
    dobkeratops, it already works in rust
  • dobkeratops
    KiChjang ah let me check with an example
  • KiChjang
    in fact, most of the time you don't even need to explicitly type (&foo).bar()
  • KiChjang
    you can simply foo.bar() and that's it
  • dobkeratops
    i know it works for receivers;
  • dobkeratops
    my quetsion is: similar auto-borrow for operator arguments and function arguments
  • KiChjang
    playbot-mini, fn main() { let foo = &5; println!("{}", 1 + foo); }
  • playbot-mini
    6
  • KiChjang
    dobkeratops, ^
  • dobkeratops
    i know that works aswell
  • KiChjang
    playbot-mini, fn main() { let foo = 5; println!("{}", 1 + foo); }
  • playbot-mini
    6
  • dobkeratops
    because you've got the operator defined for &T &T
  • dobkeratops
    thats not the same as this:
  • dobkeratops
    impl... Vector3 { fn add(&self, rhs:&Vector3)->Vector3{...} }
  • dobkeratops
    let a:Vector3.. b:Vector3; ... a+b
  • KiChjang
    i think that &Vec<T> should really be &[T]
  • dobkeratops
    thats what i'm after
  • dobkeratops
    vector3 as in "struct Vector3<T> { x:T,y:T,z:T}"
  • KiChjang
    i'm not very fond of the idea tbh
  • KiChjang
    because when i'm reading the code, it looks as if the vector is moved into the function
  • KiChjang
    when it is actually just a borrow
  • dobkeratops
    the problem is Borrow is the most common way to use something... I'd rather have to write something sepcial for move
  • dobkeratops
    that might be one way to deal with it... what if -just as you can say a type is "Copy", you could *disable* move (and require an explicit move syntax when you want that)
  • Jtremback-M
    is there a way to get rust to pretty print structs with newlines?
  • cbreeden
    dobkeratops: that idea kind of reminds me of the "smart" match rfc
  • KiChjang
    that sounds like a lifetime nightmare
  • dobkeratops
    KiChjang these are almost always trivial lifetimes.
  • dobkeratops
    operator overloading is easy in terms of lifetimes
  • dobkeratops
    nothing is retained by the function
  • dobkeratops
    (again that is something I want to be able to say 'easily')
  • dobkeratops
    "this is a function where you do not have to worry about lifetimes: no input lives beyond the function - all outputs are generated independently"
  • dobkeratops
    cbreeden i recall reading demand for a 'single match function sugar', is smart match something else?
  • KiChjang
    that already happens when you don't return a struct with a lifetime, or a reference
  • Kingsquee
    I really wish {integer} was a proper trait
  • dobkeratops
    then my suggestion wont be "a lifetime nightmare"; the context is this sort of thing (&Vector3+&Vector3 -> Vector3)
  • cbreeden
    dobkeratops: match my_thing { Thing::Foo(a, b) => { ... } } desugars to `match my_thing { Thing::Foo(ref a, ref b) ... }` as appropriate
  • cbreeden
    but what you are saying is a little bit different
  • Arnavion
    Kingsquee: The num crate has traits like that
  • KiChjang
    dobkeratops, i don't think so, because you're forgetting the case where you do want to return a &Vector3
  • dobkeratops
    KiChjang that would be clear in the signature
  • dobkeratops
    that would probably be some named function rather than an operator overload
  • dobkeratops
    operator overloads generate new values
  • dobkeratops
    "closest_point(&v1,&v2, &refpoint)->&Vector3" ... fair enough
  • KiChjang
    i'm more concerned about "doing something special to move"
  • dobkeratops
    but "v1+v2" ... "v1+v2*factor" etc ... thats all trivial
  • dobkeratops
    KiChjang why would that be any worse, if you had to enable it
  • cbreeden
    dobkeratops: does your idea boil down to something like this: `fn foo(x: &Thing); let n = Thing::new(); foo(n); /* desugars to foo(&n) */`
  • KiChjang
    right, there's one more problem
  • dobkeratops
    cbreeden yes exactly
  • KiChjang
    you need to know how to differentiate between &mut and &
  • dobkeratops
    KiChjang again I've got no problem with explicit &mut , thats good
  • cbreeden
    dobkeratops: this has been discussed actually. And I _think_ that one idea is to then drop `n` as well (sense there is ownership semantics here).
  • dobkeratops
    i'm talking about immutable borrowed arguments, which is the most common operand type (in my code) by far
  • dobkeratops
    cbreeden wait let me check what you actually said again heh
  • cbreeden
    like, I think there was talking about doing this but.. `foo(n); /* desugars to foo(&n) */ foo(n); /* compile time error */`
  • dobkeratops
    cbreeden my idea is simply this: given fn foo(x:&Bar){}; ... let a:Bar..; foo(a) // desugars to foo(&a)
  • cbreeden
    right
  • dobkeratops
    ok great
  • dobkeratops
    i wouldn't mind it being an opt-in
  • cbreeden
    dobkeratops: but that has semantics that ownership of `a` was given, and so you no longer have access to `a`
  • dobkeratops
    #[autoborrow] etc
  • KiChjang
    that's what the previous RFC is about
  • dobkeratops
    its a strange thing
  • cbreeden
    idk, maybe i'm making this up. I should look
  • KiChjang
    but what dobkeratops is suggesting now is to automatically desugar into foo(&a), and keep the ownership for the callee
  • dobkeratops
    rust has so many amazing features but can look/feel strangely clunky, the intuition of being back in C-land fires up when you see so many &'s
  • KiChjang
    caller*
  • dobkeratops
    KiChjang right, it's just inserting the &... just as we already do for receiver calls to &self
  • dobkeratops
    it could even be restricted just to operator overloading, if you're worried about the intuition of what functions do
  • dobkeratops
    it's not normal for arithmetic to "take ownership"
  • dobkeratops
    matViewProj = matView*matProj
  • KiChjang
    how about the + operator for strings?
  • dobkeratops
    again I would expect that to generate new values. += is a differnt story
  • dobkeratops
    (tangentially I would prefer a different concatenation operator :) )
  • dobkeratops
    (i like the fact haskell has a dedicated concat operator)
  • dobkeratops
    make a binary ++ :)
  • dobkeratops
    i imagine under my suggestion you might need a dedicated foo.move() just as we say foo.clone() for something C++ does automatically
  • dobkeratops
    (i.e. if we could flag a type as "autoborrow")
  • dobkeratops
    it's a really strange sensation
  • KiChjang
    that really doesn't sound like an improvement
  • dobkeratops
    rust has many amazingly elegant features but when it comes to the core of doing 3d maths I still prefer how this looks in C++ .... I think a few language tweaks could fix this
  • KiChjang
    i feel like this is breaking the symmetry for the language
  • dobkeratops
    KiChjang it would allow completeness
  • KiChjang
    especially the &mut T vs &T part
  • dobkeratops
    &mut being explicit - thats fine
  • KiChjang
    and that we need to be more verbose for .move()
  • dobkeratops
    only if you ask for it
  • KiChjang
    yeah, so why is &mut T explicit by &T not?
  • dobkeratops
    because &mut is more important to know, r.e. side-effects
  • dobkeratops
    it is not intuitive for "a+b" to have a side effect on a or b
  • KiChjang
    how is this better than what we currently have when we just need to prepend & for immutable references, and no extra syntax for moves?
  • dobkeratops
    if there is a side effect, yes the code should shout about it
  • KiChjang
    it's not intuitive for the language to be asymmetrical here
  • dobkeratops
    i'm suggesting tailoring types to their most common use. Vector maths types are borrowed, and not mutated most of the time.
  • dobkeratops
    and for the past 20 years I've had a mainstream language that lets me do that
  • dobkeratops
    now I do like how rust handles immutability
  • dobkeratops
    but i'm finding myself hitting all these discomfort points losing things I take for granted
  • dobkeratops
    if we can select 'copy', why not an option to select 'autoborrow', just as we already have for receivers
  • dobkeratops
    it's weird that I can save myself a & only for one arguemnt :) *that* is asymetry
  • dobkeratops
    matViewProj = matView.mul(&matProj) // why didn't I have to say (&matView . mul(&matProj))
  • dobkeratops
    i guess I would be happy to restrict 'autoborrow' to immutable operator arguments. "let matViewProj = matView*matProj"
  • KiChjang
    you're actually introducing more asymmetry here, because you don't need an explicit &mut matView to call mul either if it's mutable
  • KiChjang
    i.e. a method taking in &mut self can just have the syntax of foo.bar()
  • KiChjang
    but not other kinds of parameters
  • dobkeratops
    we already have this with receivers
  • dobkeratops
    but anyway, my use case doesn't care about mutability
  • KiChjang
    yes, because it's consistent with &T
  • dobkeratops
    I dont expect operators to mutate their operatonds, unless I see += etc, then it's very different
  • dobkeratops
    so foo+=bar is just like an autoborrow &mut self
  • dobkeratops
    I dont see this being a problem at all
  • dobkeratops
    you could even say "+ can't have mutable args", infact is that already the case via traits
  • dobkeratops
    so if this is just for operators, this is a non issue
  • dobkeratops
    a+b // nothing is mutated.
  • dobkeratops
    a+=b //a is mutate
  • zac
    hi, my code can be found here ( github.com/OffBlockway/mining-client ), when i boot up the server with cargo run, one of the options is a construct command which ( for now ) should just give the user a random trivia question based on structures i made that query a json file
  • zac
    however when i try and use those structures i get this error: thread 'main' panicked at 'Failed to convert JSON to Archive: ErrorImpl { code: EofWhileParsingValue, line: 1, column: 0 }', src/libcore/result.rs:906:4 note: Run with `RUST_BACKTRACE=1` for a backtrace.
  • zac
    specifically the "failed to convert JSON" is coming from the Archive struct in src/json.rs
  • zac
    could anybody help me resolve this issue?
  • Arcaelyx
    Anyone know where I could get rust docs for offline use?
  • Mutabah
    I think rustup can download them?
  • Mutabah
    yes, `rustup doc`
  • zac
    hi, my code can be found here ( github.com/OffBlockway/mining-client ), when i boot up the server with cargo run, one of the options is a construct command which ( for now ) should just give the user a random trivia question based on structures i made that query a json file
  • zac
    however when i try and use those structures i get this error: thread 'main' panicked at 'Failed to convert JSON to Archive: ErrorImpl { code: EofWhileParsingValue, line: 1, column: 0 }', src/libcore/result.rs:906:4 note: Run with `RUST_BACKTRACE=1` for a backtrace.
  • Mutabah
    Sounds like there's something invalid right at the ebginning of your json
  • Mutabah
    Wait... is the file empty?
  • zac
    no it's not
  • Arcaelyx
    Mutabah: ty
  • zac
    huh it appears to be empty on my github
  • zac
    let me re push
  • zac
    because the file i have isn't empty
  • Mutabah
    zac: well, that error seems to say that the file is empty
  • Mutabah
    Or, there's something empty that is being aprsed as something
  • centril
    It would be really great if E0046 could show just a list of missing methods that can be copied into the impl so that you can immediately start implementing
  • Saethlin
  • Saethlin
    What else are you looking for?
  • centril
    Saethlin: oh strange... I got "note: `fmt` from trait: `fn(&Self, &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error>`"
  • zac
    does anyone here have familiar with the serde serialization library?
  • zac
    im having some issue with deserializing a json file currently
  • Saethlin
    centril Can you send me a playground link?
  • dtolnay
    zac: a bit
  • Saethlin
    centril Is is possible you're using an old version of the compiler?
  • centril
    Saethlin: sec. rustc 1.24.0-nightly (73bca2b9f 2017-11-28)
  • zac
    dtonlay, my code can be found here: github.com/OffBlockway/mining-client/tree/master/json
  • zac
    im currently getting this error when i try and create an Archive instance
  • zac
    thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ErrorImpl { code: Message("invalid type: map, expected a sequence"), line: 1, column: 1 }', src/libcore/result.rs:906:4 note: Run with `RUST_BACKTRACE=1` for a backtrace.
  • zac
    archive is a struct/impl in src/json.rs
  • zac
    if you have any idea what may be causing that
  • Mutabah
    zac: Soudnds like you have a json map where the type wants a list
  • zac
    yeah im just not sure where that would be coming from
  • dobkeratops
    anyon used Rust with emscripten/wasm ? I'm just trying to build this interseting sample github.com/kvark/wasm-triangle
  • dobkeratops
    just installed 'nodejs" and "emscripten sdk" for the first time, i've got the 'emsdk' commandline tool
  • Mutabah
    zac: Well, it's pointing to line 1
  • dtolnay
    zac: which file is it deserializing? I see a "log" key in the Archive struct but I don't see "log" in the json files
  • zac
    sorry the log key is confusing but that corresponds to the results in the json file
  • Woew
    Mutabah, I'll paypal you $20 to whisper C++ answers into my ear for my stupid data structures+algorithms class final tomorrow.
  • dobkeratops
    the sample readme says "cargo add target=wasm32...." but cargo tells me 'no such subcommand target"
  • zac
    it should be deserializing json/trivia.json
  • centril
  • Mutabah
    zac: Does the backtrace point to the line where you desrialise the Archive?
  • Saethlin
    centril Interesting. I don't work on the compiler, but this looks suspicious at least
  • stephen
    If I have a borrowed `s : &SomeStruct` that contains a `member : Option<String>`, I can't seem to figure out a way to do an unwrap_or with a default value for that string. `s.member.as_ref().unwrap()` works and gives me a &String, but I can't call .unwrap_or() with a default value because the literal inside the unwrap_or call doesn't live long enough.
  • dtolnay
    zac: well the "results" key in trivia.json is a JSON list
  • stephen
    But it feels like I'm doing it not the Rust way, or something.
  • dtolnay
    zac: [{"category":...}]
  • centril
    stephen: might be a "trait not defined in your crate"-thing
  • dtolnay
    zac: and Archive is a struct, not a list
  • zac
    right so im trying to load the results into a vector
  • centril
    oops, cc Saethlin ^
  • insaneinside
    Woew: I think $20 is a little low, don't you?
  • zac
    yeah i want to create an archive instance out of the json
  • Saethlin
    centril The compiler shouldn't be less helpful or just change formatting around because of the location of the trait
  • Woew
    insaneinside, if I was asking for Mutabah's connectome, I'd be a bit more generous.
  • zac
    the archive instance is a vector of questions
  • Woew
    I'm poor, though.
  • zac
    which hold all the data for each question in the results field
  • centril
    Saethlin: ofc not - I'm just hypothesising as to why the difference exists
  • dtolnay
    zac: i see, maybe try deserializing the "results" list to a Vec<Question>
  • dtolnay
    zac: and then sticking it in an Archive
  • dtolnay
    zac: because it doesn't look like there is an Archive in the json data
  • dtolnay
    zac: i.e. there is no "log" key anywhere
  • dtolnay
    zac: another way would be to put #[serde(rename = "results")] on the log field in Archive
  • dtolnay
    zac: and deserialize the whole json file to Archive
  • centril
    to anyone working on the compiler internals: is this a known issue?
  • centril
    or should I file an issue?
  • zac
    dtolnay that got rid of that error
  • zac
    but presented me with another being: thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ErrorImpl { code: Message("missing field `kind`"), line: 1, column: 261 }'
  • obi_wan
    hey guys! I've got a strange problem. I thought I should ask here before filing bug (If there is one!).
  • zac
    could that be because i called the kind field kind but in the file its called type?
  • Mutabah
    zac: That is very likely
  • obi_wan
    Here is a simple crate: pastebin.com/hAwXAzdp. but `cargo doc` doesn't generate doc for `TitleList` properly. It creates doc with only sidebar! When I change struct named `Title` to anything else, say `Movie`, things work fine.
  • dtolnay
    zac: right, Question requires a "kind" field and the json does not have a "kind" field anywhere
  • zac
    my only issue is that type isn't a viable rust allows
  • zac
    so how could i load that json field into the struct?
  • zac
    variable*
  • Mutabah
    zac: you can use #[serde(rename="type")] as an attribute on that field
  • zac
    mutabah i implemented that and had to do it on a couple other fields as well
  • zac
    but now im getting the same parsing eof issue as earlier
  • zac
    although the file is definitely not empty
  • zac
    i just checked
  • Mutabah
    Where does the backtrace point?
  • zac
    thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:335:20 note: Run with `RUST_BACKTRACE=1` for a backtrace.
  • » obi_wan thinks he is invisible right now. :(
  • judson
    Is there an adapter already somewhere between hyper::server::Service and tokio_service::Service?
  • zac
    muntabah thats the only result i got from running the backtrace
  • zac
    mutabah *
  • insaneinside
    When wrapping "object-oriented" C APIs (where each "object" is a pointer-to-struct), is it considered an antipattern to write `assert!(! self.0.is_null());` at the top of each method?
  • » stephaneyfx tells obi_wan "You are visible" and subtly waves hand
  • stephaneyfx
    obi_wan: The generated doc looks ok to me. May you explain what is wrong in more details?
  • obi_wan
    stephaneyfx: here is a screenshot: imagebin.ca/v/3kcwCYcceKnN
  • stephaneyfx
    obi_wan: Oh you meant when clicking on TitleList. I can reproduce your issue. Hmm...
  • obi_wan
    When I just rename struct Title to Movie. It works.
  • obi_wan
    It's part of a larger crate, with Title and TitleList in different files. Even putting `type Movie = Title;` alongside TitleList declaration produces correct htmls.
  • stephaneyfx
    The angle brackets are not escaped for Vec<Title>. Weird.
  • obi_wan
    it has to be more than escaping angled brackets because it works fine for `Vec<Movie>`
  • stephaneyfx
    obi_wan: I can see they are not escaped for Vec<Movie> either, but as far as I know this is invalid html. You can see the "<Movie>" part is missing in the side bar.
  • obi_wan
    Yes. That too. I hadn't noticed it till now.
  • stephaneyfx
    Both chrome and firefox display this page the same way...
  • soc
    is there anything I have to keep in mind when using the winapi create?
  • soc
    I'm doing extern crate winapi;
  • soc
    but it seems it can't find anything in it: e.g. winapi::shell32 complains about shell32 not existing
  • obi_wan
    stephaneyfx: In case of Vec<Title>, there is no `<section id="main" class="content">...</section>` in html.
  • obi_wan
    in case of Vec<Movie>, it goes bonkers generating `<a href="#deref-methods">Methods from Deref&lt;Target=Vec<Movie>&gt;</a>` in html. It can't show as html escaping is improper.
  • WindowsBunny
    soc: shell32 is a separate crate
  • obi_wan
    in case of Vec<Movie> correct html generated for sidebar should've contained: `<a href="#deref-methods">Methods from Deref&lt;Target=Vec&lt;Movie&gt;&gt;</a>`
  • stephaneyfx
    obi_wan: Sorry, I got disconnected
  • stephaneyfx
    obi_wan: I'm guessing it's because <title> is a html tag so since "Vec<Title>" is not escaped, it gets interpreted as a html tag.
  • obi_wan
    np
  • WindowsBunny
    soc: So you'd have to depend on shell32-sys and do extern crate shell32; and use your shell32 stuff from there
  • obi_wan
    breifing!
  • obi_wan
    stephaneyfx: In case of Vec<Title>, there is no `<section id="main" class="content">...</section>` in html.
  • obi_wan
    in case of Vec<Movie>, it goes bonkers generating `<a href="#deref-methods">Methods from Deref&lt;Target=Vec<Movie>&gt;</a>` in html. It can't show as html escaping is improper.
  • obi_wan
    in case of Vec<Movie> correct html generated for sidebar should've contained: `<a href="#deref-methods">Methods from Deref&lt;Target=Vec&lt;Movie&gt;&gt;</a>`
  • obi_wan
    stephaneyfx: so it's more than '<title>' being part of html. It was never generated in doc html. (I'm grepping doc tiles files)
  • stephaneyfx
    obi_wan: I think it's just a bug in rustdoc and it does not escape correctly the generated Deref<T> link when T is something containing angle brackets
  • obi_wan
    I'll file a bug. I'm surprised it has escaped till date.
  • » obi_wan is surprised. It took a jedi to find this bug. :P
  • stephaneyfx_
    obi_wan: I escaped the angle brackets manually and the page looks fine after that.
  • obi_wan
    in Vec<Movie> right?
  • obi_wan
    Anyways, thanks for the help.
  • stephaneyfx
    obi_wan: (Not sure if you got that as my internet keeps going on and off, sorry) I escaped the angle brackets manually and the page displayed just fine.
Last Message: 12 minutes ago