You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now we have multiple ways to access fields, all perfectly type-safe. But the Keypath approach is much superior if you have awareness of the type at compile-time: basically the accessor will always be inlined, and you cannot construct an invalid Keypath.
What's the Keypath?
Poking at the internals of the keypath crate I find that a Keypath is just a Cow<'static, [PathComponent]>, with
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Consider the
GetPath
trait.It accepts a
&str
as returns a&dyn Reflect
(or a downcasted version).Consider keypaths. Those are type-safe versions of the stringly-typed
&str
we pass to theGetPath
methods…What if, instead of accepting an
&str
, theGetPath
methods had a different type parameter:The implementation of the
Path
trait would look as follow:Now we have multiple ways to access fields, all perfectly type-safe. But the
Keypath
approach is much superior if you have awareness of the type at compile-time: basically the accessor will always be inlined, and you cannot construct an invalidKeypath
.What's the
Keypath
?Poking at the internals of the keypath crate I find that a
Keypath
is just aCow<'static, [PathComponent]>
, withBeta Was this translation helpful? Give feedback.
All reactions