why can't I compare a &str to a Rc<String>
-
-
Replying to @mountain_ghosts
does &* on the Rc help
1 reply 0 retweets 2 likes -
Replying to @steveklabnik
yeah, just, idk why I'm surprised given the type system rules but this caught me off guard
2 replies 0 retweets 1 like -
Replying to @mountain_ghosts @steveklabnik
It's just not an impl that anyone thought to write explicitly. Auto-deref isn't ever used when satisfying traits, so unless there's an explicit `PartialEq<Rc<String>> for str`, it'll fail.
1 reply 0 retweets 7 likes -
Replying to @sgrif @mountain_ghosts
ahh
1 reply 0 retweets 1 like -
Replying to @steveklabnik @sgrif
yeah it makes more sense when you realise it's invoking a function of two arguments, and Deref doesn't mean that fn will try to find a common deref target to make the type system happy
1 reply 0 retweets 3 likes -
Replying to @mountain_ghosts @steveklabnik
Nah, it can pick one. It's just because traits are involved (and there are multiple deref targets to choose from, though it could just pick the first in the chain tbh) https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=00257fc8db0914a33c6e000a038111e8 …
2 replies 0 retweets 2 likes -
basically, http://foo.bar () - style autoderef works in generic situations, but the kind of autoderef where &*** is automatically applied to things to coerce them is far more limited: if it's generic (or even if relying too heavily on inference) it won't work
1 reply 0 retweets 0 likes -
Yup, which is kinda silly because the same rules used to decide which type is the receiver of `.bar` can be applied whenever `&` is used for argument passing
1 reply 0 retweets 1 like -
not really: in the former situation you're looking for a type -- any type -- with the method "bar". it's a simple linear search down the deref chain in the latter you're looking for a type which satisfies certain constraints, which is much trickier
3 replies 0 retweets 1 like
The method "bar" can come from a trait. In both cases the "certain constraints" you're looking to satisfy are "implements some trait". The only difference is special casing of the self type
-
-
I already have to write fmt::Debug::fmt(&foo, f) inside my recursive Debug impls instead of foo.fmt(f) when all that is known about foo is that it impls Debug so I'm guessing it's not simple
0 replies 0 retweets 1 likeThanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.