Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions exercises/custom-set/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,61 @@
use std::fmt::Debug;
use std::marker::PhantomData;

#[derive(Debug, PartialEq)]
pub struct CustomSet<T> {
// This field is here to make the template compile and not to
// complain about unused type parameter 'T'. Once you start
// solving the exercise, delete this field and the 'std::marker::PhantomData'
// import.
phantom: PhantomData<T>,
}

impl<T: Debug> CustomSet<T> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK to add <T: Debug> here, since a T is used in so many unimplemented messages? Or should it be left out?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with the Debug trait bound seems to appear in a lot of exercises. Instead of having separate discussion in every PR, would you mind creating an issue about it? So that there would be one fixed solution.

pub fn new(input: &[T]) -> Self {
unimplemented!(
"From the given input '{:?}' construct a new CustomSet struct.",
input
);
}

pub fn contains(&self, element: &T) -> bool {
unimplemented!(
"Determine if the '{:?}' element is present in the CustomSet struct.",
element
);
}

pub fn add(&mut self, element: T) {
unimplemented!("Add the '{:?}' element to the CustomSet struct.", element);
}

pub fn is_subset(&self, other: &Self) -> bool {
unimplemented!(
"Determine if the CustomSet struct is a subset of the other '{:?}' struct.",
other
);
}

pub fn is_empty(&self) -> bool {
unimplemented!("Determine if the CustomSet struct is empty.");
}

pub fn is_disjoint(&self, other: &Self) -> bool {
unimplemented!(
"Determine if the CustomSet struct and the other struct '{:?}' are disjoint.",
other
);
}

pub fn intersection(&self, other: &Self) -> Self {
unimplemented!("Construct a new CustomSet struct that is an intersection between current struct and the other struct '{:?}'.", other);
}

pub fn difference(&self, other: &Self) -> Self {
unimplemented!("Construct a new CustomSet struct that is a difference between current struct and the other struct '{:?}'.", other);
}

pub fn union(&self, other: &Self) -> Self {
unimplemented!("Construct a new CustomSet struct that is an union between current struct and the other struct '{:?}'.", other);
}
}