rust - How do I implement a trait for all types for which Default is implemented plus for raw pointers? -


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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -