rust - How do I implement a trait for all types for which Default is implemented plus for raw pointers? -
this question has answer here:
- why “conflicting implementations of trait” f32 not implement ord? 1 answer
- how there conflicting implementation of `from` when using associated type? 1 answer
- conflicting implementations of trait in rust 1 answer
- why trait implementation box<t> conflict fn()? 1 answer
- implement trait iterator+clone: conflicting implementations 1 answer
i want implement trait foo
types default
implemented, plus raw pointers:
use std::ptr; trait foo<t> { fn value() -> t; } impl<t: default> foo<t> t { fn value() -> t { t::default() } } impl<t> foo<*const t> *const t { fn value() -> *const t { ptr::null() } }
this not work:
error[e0119]: conflicting implementations of trait `foo<*const _>` type `*const _`: --> src/main.rs:13:1 | 7 | / impl<t: default> foo<t> t { 8 | | fn value() -> t { 9 | | t::default() 10 | | } 11 | | } | |_- first implementation here 12 | 13 | / impl<t> foo<*const t> *const t { 14 | | fn value() -> *const t { 15 | | ptr::null() 16 | | } 17 | | } | |_^ conflicting implementation `*const _`
i'm implementing raw pointers because there no default
them. not important value default::default
returns, somehow possible inform compiler 2 implementations not conflict each other, impl<u: !default>
?
is possible solution implement foo
separately each concrete type hand (or of macros)?
Comments
Post a Comment