Questions tagged «higher-rank-types»


4
如何从高阶特征绑定特征返回关联类型?
我有一个特征,具有反序列化关联类型的功能。但是,该关联类型必须具有调用者确定的生存期,因此我有一个单独的特征,我使用了绑定到其上的更高等级的特征,以便可以在任何生命周期中反序列化它。 我需要使用返回此关联类型的闭包。 我有以下代码可以做到这一点: #![allow(unreachable_code)] use std::marker::PhantomData; trait Endpoint: for<'a> EndpointBody<'a> {} trait EndpointBody<'a> { type Out: 'a; fn serialize(body: &Self::Out) -> Vec<u8>; fn deserialize(raw_body: &'a [u8]) -> Self::Out; } // ///////////////////////////////////////////////////////// /// Trait object compatible handler trait Handler { fn execute(&self, raw_body: &[u8]) -> Vec<u8>; } /// Wraps a function …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.