-
Notifications
You must be signed in to change notification settings - Fork 213
Make DataResponse
constructible from &'static M::Yokeable
#3020
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
I took a stab at this, but |
Yeah I htink it would be quite complex, I'm not sure if it's worth it. |
I'd like to see this, and I do think it will have good ROI, but if it's too hard to do while keeping API stable, let's just block it on 2.0 |
I guess I might not actually understand what you are proposing here |
The problem is that DataPayload is pub struct DataPayload<M>
where
M: DataMarker,
{
pub(crate) yoke: Yoke<M::Yokeable, Option<Cart>>,
} AnyPayload is /// Representations of the `Any` trait object.
///
/// **Important Note:** The types enclosed by `StructRef` and `PayloadRc` are NOT the same!
/// The first refers to the struct itself, whereas the second refers to a `DataPayload`.
#[derive(Debug, Clone)]
enum AnyPayloadInner {
/// A reference to `M::Yokeable`
StructRef(&'static dyn Any),
/// A boxed `DataPayload<M>`.
///
/// Note: This needs to be reference counted, not a `Box`, so that `AnyPayload` is cloneable.
/// If an `AnyPayload` is cloned, the actual cloning of the data is delayed until
/// `downcast()` is invoked (at which point we have the concrete type).
#[cfg(not(feature = "sync"))]
PayloadRc(SelectedRc<dyn Any>),
#[cfg(feature = "sync")]
PayloadRc(SelectedRc<dyn Any + Send + Sync>),
}
/// A type-erased data payload.
///
/// The only useful method on this type is [`AnyPayload::downcast()`], which transforms this into
/// a normal `DataPayload` which you can subsequently access or mutate.
///
/// As with `DataPayload`, cloning is designed to be cheap.
#[derive(Debug, Clone, Yokeable)]
pub struct AnyPayload {
inner: AnyPayloadInner,
type_name: &'static str,
} AnyPayload avoids calling ZeroFrom with the extra variant, but we still need to ZeroFrom when converting to DataPayload. |
We could resolve this if we made DataPayload have two variants, a |
There's currently no |
Good point. We could perhaps add a ZeroFrom bound on the relevant methods, but that's a 2.0 change. Let's hold this until then. |
Originally posted by @sffc in #2906 (comment)
The text was updated successfully, but these errors were encountered: