【发布时间】:2015-04-20 18:54:58
【问题描述】:
我有点卡在一些代码上,http://is.gd/OMvnN7:每晚的错误修复使其无效(有充分的理由:https://github.com/rust-lang/rust/pull/24461),但我没有看到任何替代方法可以让我的代码运行。
关键是我的关联类型“SignedContent”大部分时间都有一个关联的生命周期,但我不想将此生命周期绑定到它的父特征(对现有代码的影响很可能是每个特征都使用这个特征(很多)需要一个额外的生命周期参数,看起来不太实用)。
我可能会直接切换到返回 Vec<u8> 的“get_sign_content”,但我更喜欢返回可编码的结构。
唯一缺少的是表达我的关联类型生命周期绑定与其父级相同,类似的东西(无效)
impl TrustedVal for RSAPeer
{
type SignedContent = TrustedPeerToSignEnc<'Self::lifetime>;
或者
impl<'a> TrustedVal for RSAPeer where RSAPeer : 'a
{
type SignedContent = TrustedPeerToSignEnc<'a>;
我也考虑过(这是有效的)
impl<'a> TrustedVal for &'a RSAPeer
{
type SignedContent = TrustedPeerToSignEnc<'a>;
但是使用其他一些代码会变得非常尴尬。有什么正确设计方法的想法吗?
【问题讨论】:
-
据我所知,实现原始形式的唯一方法是使用(有限形式的)更高种类的类型,允许使用
trait TrustedVal { type SignedContent<'a>: Encodable; fn get_sign_content(&'a self) -> Self::SignedContent<'a>; }、impl TrustedVal for RSAPeer { type SignedContent<'a> = TrustedPeerToSignEnc<'a>; ...之类的东西。不幸的是,此功能现在/尚不存在。 -
原来是这样的。