-
Notifications
You must be signed in to change notification settings - Fork 229
[Question]How to extract generic type values #491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
There are no useful values of types capnproto-rust/capnp/src/traits.rs Lines 51 to 64 in 528b64b
|
impl<K, V> From<entry::Reader<'_, K, V>> for (K, V)
where
K: capnp::traits::Owned,
V: capnp::traits::Owned,
{
fn from(value: crate::map_capnp::entry::Reader<'_, K, V>) -> Self {
let key: <K as Owned>::Reader = value.get_key().unwrap();
let value: <V as Owned>::Reader = value.get_value().unwrap();
todo!()
}
} Thanks for the quick response, so if I understand correctly, the generic types impl <CapnK, CapnV, RustK, RustV> From<Entry<'_, CapnK, CapnV>> for (RustK, RustV) and there should be a trait bound that one can convert a where RustK: From<<CapnK as Owned>::Reader> |
Hi, I am curious if the approach presented in my last comment is feasible, it seems there is no general abstraction (traits or methods) to extract the |
Correct. Generic type in Cap'n Proto messages can only be instantiated with Cap'n Proto types.
That's correct. In #157 there was some work towards proc macros that convert between capnproto and rust-native types. That got turned into its own repo (which I have not looked at in depth): https://github.com/aikalant/capnp_conv |
Yeah, that crate defines 2 helper traits like: pub trait Writable {
type OwnedType: capnp::traits::Owned;
fn write(&self, builder: <Self::OwnedType as Owned>::Builder<'_>);
}
pub trait Readable
where
Self: Sized,
{
type OwnedType: capnp::traits::Owned;
fn read(reader: <Self::OwnedType as Owned>::Reader<'_>) -> Result<Self>;
} so that one can do Thanks for the response! |
Hi! Thanks for this amazing project!
I would like to know how I can extract the value of a generic type from its
Reader
type.For example, for the following
Entry
type:I want to implement
From<entry::Reader<'_, K, V> for (K, V)
:As you can see, I can access their
Reader
types, but how can I extra their values, i.e., values of typeK
andV
, thanks!The text was updated successfully, but these errors were encountered: