forked from URI-ABD/clam
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added dataset extension traits for working with metadata
- Loading branch information
Showing
17 changed files
with
175 additions
and
90 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,46 @@ | ||
//! An extension of the `Dataset` trait that provides methods for working with | ||
//! metadata associated with items in a dataset. | ||
use super::Dataset; | ||
|
||
/// A trait that extends the `Dataset` trait with methods for working with | ||
/// metadata associated with items in a dataset. | ||
/// | ||
/// Each item in the dataset should be associated with a piece of metadata. | ||
/// | ||
/// # Type parameters | ||
/// | ||
/// - `I`: The type of the items in the dataset. | ||
/// - `Me`: The type of the metadata associated with each item in the dataset. | ||
pub trait AssociatesMetadata<I, Me>: Dataset<I> { | ||
/// Returns the all metadata associated with the items in the dataset. | ||
fn metadata(&self) -> &[Me]; | ||
|
||
/// Returns the metadata associated with the item at the given index. | ||
fn metadata_at(&self, index: usize) -> &Me; | ||
} | ||
|
||
/// An extension of the `AssociatesMetadata` trait that provides methods for | ||
/// changing the metadata associated with items in a dataset. | ||
#[allow(clippy::module_name_repetitions)] | ||
pub trait AssociatesMetadataMut<I, Me, Met: Clone, D: AssociatesMetadata<I, Met>>: AssociatesMetadata<I, Me> { | ||
/// Returns the all metadata associated with the items in the dataset, | ||
/// mutably. | ||
fn metadata_mut(&mut self) -> &mut [Me]; | ||
|
||
/// Returns the metadata associated with the item at the given index, | ||
/// mutably. | ||
fn metadata_at_mut(&mut self, index: usize) -> &mut Me; | ||
|
||
/// Changes all metadata associated with the items in the dataset. | ||
/// | ||
/// # Errors | ||
/// | ||
/// - If the number of metadata items is not equal to the cardinality of the | ||
/// dataset. | ||
fn with_metadata(self, metadata: &[Met]) -> Result<D, String>; | ||
|
||
/// Applies a transformation to the metadata associated with the items in | ||
/// the dataset. | ||
fn transform_metadata<F: Fn(&Me) -> Met>(self, f: F) -> D; | ||
} |
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
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
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
Oops, something went wrong.