diff --git a/src/lib.rs b/src/lib.rs index 2655352..567459d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -102,12 +102,12 @@ use backend::{Backend, MemoryBackend, FileBackend}; /// The Central Database to RustBreak /// -/// It has 5 Type Generics: +/// It has 3 Type Generics: /// -/// - V: Is the Data, you must specify this (usually inferred by the compiler) -/// - S: The Serializer/Deserializer or short DeSer. Per default `deser::Ron` is used. Check the -/// `deser` module for other strategies. -/// - F: The storage backend. Per default it is in memory, but can be easily used with a `File`. +/// - Data: Is the Data, you must specify this +/// - Back: The storage backend. +/// - DeSer: The Serializer/Deserializer or short DeSer. Check the `deser` module for other +/// strategies. #[derive(Debug)] pub struct Database where @@ -264,3 +264,28 @@ impl Database } } } + +impl Database + where + Data: Serialize + DeserializeOwned + Debug + Clone + Send, + Back: Backend, + DeSer: DeSerializer + Send + Sync +{ + /// Converts from one data type to another + /// + /// This method is useful to migrate from one datatype to another + pub fn convert_data(self, convert: C) + -> error::Result> + where + OutputData: Serialize + DeserializeOwned + Debug + Clone + Send, + C: FnOnce(Data) -> OutputData, + DeSer: DeSerializer, + { + let (data, backend, deser) = self.into_inner()?; + Ok(Database { + data: RwLock::new(convert(data)), + backend: Mutex::new(backend), + deser: deser, + }) + } +}