-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update data struct name and errors
- Loading branch information
Hugo Rosenkranz-Costa
committed
Nov 13, 2023
1 parent
b025097
commit 1466ed8
Showing
7 changed files
with
106 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use std::fmt::{Debug, Display}; | ||
|
||
type Key = String; | ||
#[derive(Debug)] | ||
pub enum Error { | ||
EntryNotFound(Key), | ||
ExistingEntry(Key), | ||
AlreadyHasChild(Key), | ||
} | ||
|
||
impl Display for Error { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match &self { | ||
Error::EntryNotFound(key) => write!(f, "Entry not found with key: {key}."), | ||
Error::ExistingEntry(key) => write!(f, "Already existing entry with key: {key}."), | ||
Error::AlreadyHasChild(key) => { | ||
write!(f, "Entry with key {key} already has a child.") | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl Error { | ||
pub fn missing_entry<T>(key: &T) -> Self | ||
where | ||
T: Debug, | ||
{ | ||
Self::EntryNotFound(format!("{:?}", key)) | ||
} | ||
|
||
pub fn existing_entry<T>(key: &T) -> Self | ||
where | ||
T: Debug, | ||
{ | ||
Self::ExistingEntry(format!("{:?}", key)) | ||
} | ||
|
||
pub fn already_has_child<T>(key: &T) -> Self | ||
where | ||
T: Debug, | ||
{ | ||
Self::AlreadyHasChild(format!("{:?}", key)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
pub mod linked_hashmap; | ||
pub mod linked_vec; | ||
|
||
pub mod error; | ||
|
||
use linked_hashmap::VersionedHashMap; | ||
use linked_vec::VersionedVec; |