#rust

/

      • alisha joined the channel
      • indy has quit
      • indy joined the channel
      • j0nthn joined the channel
      • abhi joined the channel
      • abhi has left the channel
      • dionysus69 joined the channel
      • kzan has quit
      • kzan joined the channel
      • jrozner joined the channel
      • bholley has quit
      • kzan has quit
      • kzan joined the channel
      • neachdainn joined the channel
      • roc has quit
      • italic has quit
      • kvlm joined the channel
      • mgottschlag has quit
      • eris314_ joined the channel
      • tbodt joined the channel
      • ssokolow
        I just ran into something which I'm uncertain of and the compiler isn't giving any useful hints.
      • neachdainn has quit
      • Clippy pointed out that I'm using `while let Some(...) = self.in_iter.next()`, but changing it to `for ... in self.in_iter` throws up a `cannot move out of borrowed content` error.
      • Maybe I'm just too tired, but I'm stumped.
      • mthjones has quit
      • SpaceManiac
        for ... in self.in_iter().as_ref() may work
      • OmniMancer joined the channel
      • if it doesn't, then the warning is spurious
      • eris314_ has quit
      • marsel has quit
      • McDirty joined the channel
      • ssokolow
        in_iter isn't a method and "self.in_iter.as_ref()" fails with "no method named `as_ref` found for type `unicode_segmentation::GraphemeIndices<'a>` in the current scope"
      • jkonecny joined the channel
      • jrozner has quit
      • scottmcm
        ssokolow: maybe `for ... in &mut self.in_iter`?
      • jrozner joined the channel
      • SpaceManiac
        sorry, the thing I was thinking of was .by_ref()
      • ssokolow
        No, that fails because there's a mutable borrow of another member of self within the loop body.
      • SpaceManiac
        in that case, the Clippy warning is spurious
      • ssokolow
        ...but thanks for prompting me to realize that & giving a "the trait `std::iter::Iterator` is not implemented for `&unicode_segmentation::GraphemeIndices<'_>`" error doesn't also mean the same error would be produced by &mut.
      • scottmcm
        (There's a blanket `impl<'a, I> Iterator for &'a mut I where I: Iterator + ?Sized`)
      • evilman_work has quit
      • McDirty has quit
      • Manishearth
        ssokolow: try for ... in &self.in_iter()
      • quimrstorres joined the channel
      • scottmcm
        !gh 42265
      • rustbot
        [PR 42265] <merged> Change for-loop desugar to not borrow the iterator during the loop <https://github.com/rust-lang/rust/pull/42265>;
      • kbsymanz joined the channel
      • Hoff joined the channel
      • ssokolow
        Manishearth: Again, in_iter() isn't a method. That said, I already tried `for ... in &self.in_iter` and got the aforementioned "the trait `std::iter::Iterator` is not implemented for `&unicode_segmentation::GraphemeIndices<'_>`"
      • aarjan has quit
      • scottmcm
        Hmm, do you exhaust the iterator? You could mem::replace it if so...
      • ssokolow
        No, I iterate until I hit a word boundary, then return until the next time this next() is called.
      • osa1 joined the channel
      • Honestly, it's looking like the best solution is slapping an allow() onto the `while let Some(...) = self.in_iter.next()` I stumbled upon without realizing the bullet I'd dodged.
      • monad joined the channel
      • ShadowIce joined the channel
      • quimrstorres has quit
      • wuwei has quit
      • ...and blogging about how it serves as a not-at-all-obvious way to consume an iterator bound to a `self` member without taking a mutable borrow on `self` for the duration of the loop body.
      • scottmcm
        Aren't mutable borrows to different fields disjoint?
      • urodna has quit
      • tbodt has quit
      • zapwai has quit
      • ssokolow
        scottmcm: Inside the loop body, I'm calling an `&must self` method.
      • s/must/mut/
      • z3t0 joined the channel
      • eris314_ joined the channel
      • scottmcm
        ah. (above said "of another member of self", so I was confused.)
      • tbodt joined the channel
      • connicpu has quit
      • ssokolow
        *nod* I should have been more clear there.
      • That said, in hindsight, the approach I stumbled upon completely by accident is very clever. Directly call .next() in a `while let` loop and the only thing the body holds onto is the returned item.
      • nicholasf has quit
      • z3t0 has quit
      • z3t0 joined the channel
      • nicholasf joined the channel
      • periklis has quit
      • remexre
        Is the issue with TryFrom just that we want ! to exist for the inherent impls, or is there something else, too?
      • (the issue with == the reason it's not in stable)
      • scottmcm
        ssokolow: Yup. And I can't think of a different loop sugar that could do that, unless it detected "you have me an lvalue that's Iterator, so I'll skip the IntoIterator call and just use it"
      • eris314_ has quit
      • remexre: I recall a general disagreement about what the error types should actually be in mixed cases
      • scottmcm thinks that the Error type for something infallible should obviously be `!`, but that's not universal
      • yangby joined the channel
      • remexre
        Yeah, it feels like an "of course it is" thing
      • kulshrax has quit
      • kulshrax joined the channel
      • scottmcm
        remexre: I could also imagine something like removing the Result requirement by using Try
      • Trangar joined the channel
      • kulshrax has quit
      • remexre
        ?
      • kulshrax joined the channel
      • LCPolan has quit
      • ryzokuken joined the channel
      • scottmcm
        trait TryFrom<T> { type Output : Try<Ok=Self>; fn try_from(value:T) -> Self::Output; }
      • remexre
        Oh, is that the ? operator's trait?
      • scottmcm
        Yup, as of a fairly recent RFC
      • !gh rfcs 1859
      • rustbot
        [PR 1859] <merged> extend `?` to operate over other types <https://github.com/rust-lang/rfcs/pull/1859>;
      • scottmcm
        It would mean you could return Option from TryFrom if you wanted
      • remexre
        And then Try::Error would just be () ?
      • scottmcm
        It's also a little crazy, so I don't know if it's a good idea :P
      • remexre: it's be std::option::NoneError (or something like that -- see the discussion of `Missing` in the RFC)
      • Arcaelyx_ joined the channel
      • Andoriyu joined the channel
      • remexre
        Okay, I'm only a couple paragraphs in :)
      • scottmcm
        !gh 42526
      • rustbot
        [PR 42526] <open> Impl Try for Option <https://github.com/rust-lang/rust/pull/42526>;
      • scottmcm
        ^ Open PR for allowing `?` on Option :)
      • Philpax joined the channel
      • yangby has quit
      • remexre
        Eh, I feel like I'm more in favor of Result in TryFrom still
      • Try feels like it's sugar for Into<Result>
      • Arcaelyx has quit
      • ambaxter joined the channel
      • ayujup joined the channel
      • Muhannad joined the channel
      • rhn joined the channel
      • mmacy
        ?(x="foo") is how Ocaml marks optional arguments
      • under the covers they're converted in to an Option
      • sethlopez joined the channel
      • ambaxter has quit
      • and it generates code that does Some(x) => x, None => "foo"
      • Muhannad has quit
      • Shibe
        hello guys cargo seems to be stuck in some sort of loop during "updating registry" because its eating my cpu and taking forever
      • Muhannad joined the channel
      • mmacy
        can you strace it?
      • scottmcm
        Do you have a virus scanner active in its cache folder?
      • mmacy
        ooh
      • windows file locking
      • Shibe
      • mmacy
        that's always a recipe for awesomeness
      • Shibe
        it finally returned
      • and also i'm not using windows thankfully
      • seems to be some libc stuff. thought it might be related to dependencies so i posted the cargo.toml also
      • quimrstorres joined the channel
      • help me please! i decided to be productive for once and this stuff happens
      • wizwizwizwiz has quit
      • eris314_ joined the channel
      • scottmcm
        Does it happen every time? The registry update should be small subsequently...
      • dex joined the channel
      • sleffy has quit
      • Shibe
        scottmcm: right now i'm running cargo update and rebuilding
      • it didnt hang this time