mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-09-25 06:09:44 +00:00
Create a new trait
This commit is contained in:
16
src/api_data/entities_constructor.rs
Normal file
16
src/api_data/entities_constructor.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
//! # Entities constructor
|
||||
//!
|
||||
//! This trait simplify the construction of new items
|
||||
|
||||
pub trait EntitiesConstructor {
|
||||
type Item;
|
||||
|
||||
/// Turn a server item into an API entry
|
||||
fn new(i: &Self::Item) -> Self;
|
||||
|
||||
/// Parse a list of it
|
||||
fn for_list(l: &Vec<Self::Item>) -> Vec<Self>
|
||||
where Self: std::marker::Sized {
|
||||
l.iter().map(Self::new).collect()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user