-
15 votesanswersviews
无法在Swift中创建符合协议的类型数组
我有以下协议和符合它的类: protocol Foo{ typealias BazType func bar(x:BazType) ->BazType } class Thing: Foo { func bar(x: Int) -> Int { return x.successor() } } 当我尝试创建一个foos数组时,我得... -
4 votesanswersviews
Swift关联类型和协议继承
我正在使用Swift 2.2并且我声明了一个具有相关类型的协议如下: protocol CollectionViewModeling { associatedtype CellType func cellAtIndexPath(indexPath: NSIndexPath) -> CellType } 现在我有一个符合上述协议的视图模型协议: enum MyItemCell... -
2 votesanswersviews
没有关联类型,但是:协议只能用作通用约束,因为它具有Self或关联类型要求[重复]
这个问题在这里已有答案: What does “Protocol … can only be used as a generic constraint because it has Self or associated type requirements” mean? 2个答案 Usage of protocols as array types and function parameter... -
0 votesanswersviews
协议'BaseListPresenter'只能用作通用约束,因为它具有Self或关联类型要求
我正在定义一个具有某些功能和变量的协议 protocol BaseListPresenter { associatedtype T var values: [T] {get} } extension BaseListPresenter { public func count() -> Int { return values.count } ... -
2 votesanswersviews
实现具有相关特征类型的特征
我在学习相关类型时遇到了麻烦 . 我的问题代码: trait Fooer { fn foo(&self); } trait FooStore { type T: Fooer; fn store_foo(&self, fooer: Self::T); } #[allow(dead_code)] struct DB {} impl FooStore for... -
2 votesanswersviews
如何包装具有相关类型的特征?
我对Rust很新,所以我的术语可能很混乱 . 我想使用hashes crates进行一些散列,我想动态选择在运行时使用哪种算法(sha256,sha512等) . 我想写这样的东西: let hasher = match "one of the algorithms" { "sha256" => Box::new(Sha256::new()) ... -
252 votesanswersviews
使用模板Haskell获取关联的类型同义词
模板Haskell可以找出类型类中声明的关联类型同义词的名称和/或声明吗?我希望reify可以做我想要的,但它似乎没有提供所有必要的信息 . 它适用于获取函数类型签名: % ghci GHCi, version 7.8.3: http://www.haskell.org/ghc/ :? for help ... Prelude> -- I'll be inserting line brea...