Вход на сайт

Просмотр новости

Найдите то, что Вас интересует

Trait object with associated types in field - requires generic param?

Дата публикации: 07-10-2026 16:02:43


I currently have:
trait ListModel {
fn get_stuff(&self, row: i) -> Stuff;
...
}
struct List {
model: Rc<dyn ListModel>,
...
}
I think I want to change my model to use row IDs instead of usize indices. If I do this:
trait ListModel {
type Key: Eq + Hash + Clone;
fn get_stuff(&self, row: Key) -> Stuff;
}
There is no way to keep List non-generic, correct? I need to have something like these? :
struct List<M: ListModel> {
model: Rc<M>,
}
// or
struct List<K> {
model: Rc<dyn ListModel<Key = K>>,
...
}
3 posts - 3 participants
Read full topic

Схожие новости

#Наименование новостиТональностьИнформативностьДата публикации
1Strategies for dyn trait objects with optional behavior?07.1206-10-2026
2Why no Dependent Matrix Type?05.1608-10-2026
3Type erasure and dyn lifetime in a NonNull/Box struct field08.5504-10-2026
4Limitations of `min_specialization` when specializing a generic implementation?09.3804-10-2026
5Crate async_trait - error future created by async block is not Send05.405-10-2026
6Arena's and alignment07.304-10-2026
7Optimization of inlined functions returning Result?07.3606-10-2026
8Why is f32/f64::sqrt not const?022.7206-10-2026
9What's everyone working on this week (41/2026)?020.3406-10-2026
10Array initialization post declaration016.7906-10-2026

Классификация: . Схожих патентов: 0. Схожих новостей: 10. Тональность: 0. Информативность: 11.08. Источник: users.rust-lang.org.