Skip to content

Commit

Permalink
add design notes
Browse files Browse the repository at this point in the history
  • Loading branch information
dwrensha committed Sep 23, 2024
1 parent 436de1b commit d1d3b01
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions capnp/src/dynamic_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ impl<'a> Reader<'a> {

/// Downcasts the `Reader` into a specific struct type. Panics if the
/// expected type does not match the value.
///
/// Design note: instead of this method, it would be better to add a blanket impl
/// of the `DowncastBuilder` trait that covered every struct type. Unfortunately,
/// the current way the `Introspect` and `OwnedStruct` traits are set up does not
/// seem to allow this.
pub fn downcast_struct<T: crate::traits::OwnedStruct>(self) -> T::Reader<'a> {
let sr: dynamic_struct::Reader = self.downcast();
let TypeVariant::Struct(rs) = T::introspect().which() else {
Expand Down Expand Up @@ -231,6 +236,11 @@ impl<'a> Builder<'a> {

/// Downcasts the `Builder` into a specific struct type. Panics if the
/// expected type does not match the value.
///
/// Design note: instead of this method, it would be better to add a blanket impl
/// of the `DowncastBuilder` trait that covered every struct type. Unfortunately,
/// the current way the `Introspect` and `OwnedStruct` traits are set up does not
/// seem to allow this.
pub fn downcast_struct<T: crate::traits::OwnedStruct>(self) -> T::Builder<'a> {
let sb: dynamic_struct::Builder = self.downcast();
let TypeVariant::Struct(rs) = T::introspect().which() else {
Expand Down

0 comments on commit d1d3b01

Please sign in to comment.