exercise: doubly-linked-list
#[allow(unused)]
#[cfg(feature = "advanced")]
/// ```compile_fail
/// use doubly_linked_list::LinkedList;
/// trait AssertSend: Send {}
/// impl<T> AssertSend for LinkedList<T> {}
/// ```
pub struct IllegalSend;
#[allow(unused)]
#[cfg(feature = "advanced")]
/// ```compile_fail
/// use doubly_linked_list::LinkedList;
/// trait AssertSync: Sync {}
/// impl<T> AssertSync for LinkedList<T> {}
/// ```
pub struct IllegalSync;
There are some code in doc within pre_implemented.rs, but marked compile_fail.
When advanced is open, it should be success otherwise tests can not be pass.
The diff between doc and test prevent me to commit code.
These tests are correct. If they fail, then your solution is wrong.
I passed the test, but these doc did not, either all pass or all fail.
fn advanced_linked_list_is_send_sync() {
trait AssertSend: Send {}
trait AssertSync: Sync {}
impl<T: Send> AssertSend for LinkedList<T> {}
impl<T: Sync> AssertSync for LinkedList<T> {}
}
fn code_in_doc() {
use doubly_linked_list::LinkedList;
trait AssertSync: Sync {}
impl<T> AssertSync for LinkedList<T> {}
}
I think it should be #[cfg(not(feature = "advanced"))] with IllegalSync and IllegalSend, the goal of advanced is make LinkedList<T> implement Send and Sync, in this time, compile should not fail.
You have implemented Send and Sync without a trait bound, which means your linked list could be used to send or share data types that are fundamentally not thread safe. You must add the trait bound : Send and : Sync respectively.