cost 377 ms
將 object 添加到一個數組中,該數組確認其中具有關聯類型的協議

[英]Add object to an array that confirm to the protocol that has associated type in it

我在編寫將對象放入observers數組的代碼時遇到問題。 這些對象實現了Observer協議。 我想將ValueType與Subject的通用類型T聯系起來。 這是顯示我想做什么的代碼:protocol Observer { associatedtype ValueType fun ...

實現 IntoIterator 的無約束類型參數

[英]Unconstrained type parameter implementing IntoIterator

我如何使用泛型類型參數實現 IntoIterator 而不會出現這種錯誤,我認為與此處的錯誤相同,但提出的解決方案在此上下文中無效,同時在Counter上執行一個名為iter的方法可以解決問題但它不會是慣用的#[derive(Debug, Clone, Copy, PartialEq, Eq, Pa ...

如何通過協議 inheritance 使具有關聯類型的通用協議不是通用的?

[英]How to make generic protocol with associatedtype not generic via protocol inheritance?

我有具有關聯類型的通用協議,並且在某些時候想讓它不是通用的。 同樣的行為適用於類,但不幸的是我不能對協議使用相同的邏輯。 例如,這絕對沒問題: 但是使用協議我得到編譯錯誤協議“StringValidatorProtocol”只能用作通用約束,因為它具有 Self 或關聯的類型要求 有任何想法嗎? ...

在“Generic Where Clauses”中遇到錯誤,仍然無法弄清楚原因! 雖然在 swift 書中是一樣的

[英]Encountered an error in "Generic Where Clauses", still not able to figure out why! While it is same in the swift book

主題:通用 Where 子句 if-else 控制流中出現錯誤 錯誤表示“arrayOfStrings”不符合容器協議。 試了很多次還是沒弄明白 錯誤確切地說 - “全局函數 'allItemsMatch' 要求 '[String]' 符合 'Container'” ...

無法在 swift 中使用 associatedType 作為方法 returnType,因為編譯器拋出“關聯類型的模糊推斷”

[英]Unable to use associatedType as method returnType in swift as compiler throws “Ambiguous inference of associated type”

正在玩關聯類型。 使用 associatedType 時,編譯器無法識別方法的返回類型。 這是代碼示例, 並且編譯器會拋出此錯誤。 問題: (1) 屬性“subBranch”沒有發生錯誤。 也就是說,如果我沒有在協議中創建一個返回 associatedType 的方法,那么一切都會順利進行。 ...

使用泛型關聯類型時,如何指示類型參數的生命周期?

[英]How do I indicate a lifetime bound on a type parameter when using generic associated types?

我正在嘗試為具有泛型類型的結構實現具有泛型關聯類型的特征。 我正在使用每晚版本1.47.0-nightly (2020-07-20 f9a3086363f214f2b56b) 。 我有結構S1和S2 ,具有 GAT 的特征和實現:#![allow(incomplete_features)] #![ ...


排序:
質量:
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM