Comments (5)
There are no useful values of types K
and V
. The only way to interact with Cap'n Proto data is through Reader
and Builder
types. See this comment:
capnproto-rust/capnp/src/traits.rs
Lines 51 to 64 in 528b64b
from capnproto-rust.
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 K
and V
defined in the above code are CapN types, I cannot convert Entry
to a CapN (K, V)
pair, instead, I should define 2 extra Rust K
V
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 <CapnK as Owned>::Reader
to a RustK
, something like:
where RustK: From<<CapnK as Owned>::Reader>
from capnproto-rust.
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 RustK
value from the CapnK
reader type, I have to know the concrete reader type (struct_list::Reader
, dynamic_value::Reader
, etc) and call the corresponding methods to get the value.
from capnproto-rust.
the generic types K and V defined in the above code are CapN types
Correct. Generic type in Cap'n Proto messages can only be instantiated with Cap'n Proto types.
it seems there is no general abstraction (traits or methods) to extract the RustK value from the CapnK reader type
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
from capnproto-rust.
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 <RustK as Readable>::read(CapnK_reader)
to extract the value, though I didn't take a deep look either.
Thanks for the response!
from capnproto-rust.
Related Issues (20)
- Serializing message to &[u8] HOT 2
- Improve performance of Reader get_named HOT 4
- Primitive list panicks if the list type is `Void` HOT 1
- Null values for non active union members HOT 3
- Switch Allocator to act more like an owned arena HOT 8
- Reader fails with out of bounds pointer error when reading from compressed stream HOT 1
- Revert text setter ergonomics pessification; add raw_set methods HOT 6
- calculator example fails with java server: Cannot read capability pointer without capTable HOT 1
- c++.capnp compiles to unusable module name HOT 6
- How to send generated readers across threads HOT 3
- From bytes to TypedReader HOT 6
- Allowing construction of NoAllocSliceSegments with buffer and NoAllocBufferSegmentType HOT 7
- Kudos to builders of this Rust library - Every single one of you. HOT 3
- capnp_rpc does not work on monoio HOT 4
- Dynamic parsing of fields may panic HOT 1
- traits.ListIter incorrectly implementing ExactSizeIterator HOT 1
- oc
- Using same schema file for both Rust and C++ HOT 1
- doc: read_message_from_flat_slice_no_alloc docstring bad autocomplete HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from capnproto-rust.