From fd9b25579df893c7d06bff792d37647f714732d6 Mon Sep 17 00:00:00 2001 From: bloodnighttw Date: Sat, 13 Jul 2024 19:11:21 +0800 Subject: [PATCH 1/9] Add SavePath trait to utils workspace. --- reginleif-test/src/utils/save_path.rs | 64 +++++++++++++++++++++++++++ reginleif-utils/src/lib.rs | 1 + 2 files changed, 65 insertions(+) create mode 100644 reginleif-test/src/utils/save_path.rs diff --git a/reginleif-test/src/utils/save_path.rs b/reginleif-test/src/utils/save_path.rs new file mode 100644 index 0000000..8fbc54c --- /dev/null +++ b/reginleif-test/src/utils/save_path.rs @@ -0,0 +1,64 @@ +mod test{ + use std::path::PathBuf; + use serde::{Deserialize, Serialize}; + use reginleif_utils::save_path::{BaseStorePoint, Store}; + + const TEST_PATH_CONST:&'static[&'static str] = &["test"]; + + struct TestPath(PathBuf); + + impl BaseStorePoint for TestPath{ + fn get_base(&self) -> PathBuf { + self.0.clone() + } + } + + impl From for TestPath{ + fn from(path:PathBuf) -> Self{ + Self(path) + } + } + + #[derive(Deserialize,Serialize,PartialEq,Debug)] + struct A; + + impl Store<'_> for A{ + const FILE_PATH: &'static [&'static str] = TEST_PATH_CONST; + type AcceptStorePoint = TestPath; + type SelfType = Self; + + fn save(&self, base: &Self::AcceptStorePoint) -> anyhow::Result<()> { + let base_path = Self::full_path(&base); + + std::fs::create_dir_all(base_path.parent().ok_or(anyhow::anyhow!("No parent"))?)?; + std::fs::write(base_path,serde_json::to_string(self)?.as_bytes())?; + + Ok(()) + + } + + fn load(base: &Self::AcceptStorePoint) -> anyhow::Result { + + let base_path = Self::full_path(&base); + + let json = std::fs::read_to_string(base_path)?; + Ok(serde_json::from_str(&json)?) + } + + } + + #[tokio::test] + async fn test_save_load(){ + let path = PathBuf::from("test"); + let test_path = TestPath::from(path.clone()); + let a = A; + a.save(&test_path).unwrap(); + let b = A::load(&test_path).unwrap(); + assert_eq!(a,b); + + tokio::fs::remove_file(path).await.unwrap(); + } + + + +} \ No newline at end of file diff --git a/reginleif-utils/src/lib.rs b/reginleif-utils/src/lib.rs index f32eb87..a7be9ae 100644 --- a/reginleif-utils/src/lib.rs +++ b/reginleif-utils/src/lib.rs @@ -1,2 +1,3 @@ pub mod expiring_data; pub mod serde_convert; +pub mod save_path; From 86fab2655841a8d0a71090c43de81e5a06e21b9c Mon Sep 17 00:00:00 2001 From: bloodnighttw Date: Sat, 13 Jul 2024 19:11:47 +0800 Subject: [PATCH 2/9] Add Test code for save path. --- Cargo.lock | 2 ++ reginleif-test/Cargo.toml | 4 ++- reginleif-test/src/utils.rs | 3 +- reginleif-utils/src/save_path.rs | 47 ++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 reginleif-utils/src/save_path.rs diff --git a/Cargo.lock b/Cargo.lock index 91e87af..abb4c27 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -756,6 +756,8 @@ dependencies = [ "reginleif-macro", "reginleif-utils", "reqwest", + "serde", + "serde_json", "tokio", ] diff --git a/reginleif-test/Cargo.toml b/reginleif-test/Cargo.toml index 9cff23e..7e94102 100644 --- a/reginleif-test/Cargo.toml +++ b/reginleif-test/Cargo.toml @@ -20,4 +20,6 @@ reginleif-macro = {path = "../reginleif-macro"} # to test package, so not depend tokio.workspace = true reqwest.workspace = true async-trait.workspace = true -anyhow.workspace = true \ No newline at end of file +anyhow.workspace = true +serde.workspace = true +serde_json.workspace = true \ No newline at end of file diff --git a/reginleif-test/src/utils.rs b/reginleif-test/src/utils.rs index 77aecda..a7550db 100644 --- a/reginleif-test/src/utils.rs +++ b/reginleif-test/src/utils.rs @@ -1 +1,2 @@ -mod expiring_data; \ No newline at end of file +mod expiring_data; +mod save_path; \ No newline at end of file diff --git a/reginleif-utils/src/save_path.rs b/reginleif-utils/src/save_path.rs new file mode 100644 index 0000000..1a259c4 --- /dev/null +++ b/reginleif-utils/src/save_path.rs @@ -0,0 +1,47 @@ +use std::path::{Path, PathBuf}; +use serde::{Deserialize, Serialize}; + +pub trait BaseStorePoint:Sync+Send{ + /// Get the path of the data. + fn get_base(&self) -> PathBuf; +} + +pub trait ExpandStorePoint{ + fn get_suffix(&self) -> PathBuf; +} + +pub trait Store<'a>:Serialize+Deserialize<'a>{ + + const FILE_PATH:&'static [&'static str]; + /// The type of the base path you have to accept. + type AcceptStorePoint:BaseStorePoint; + /// You should assign Self to this. + type SelfType; + + fn full_path(base:&Self::AcceptStorePoint) -> PathBuf{ + let mut base_path = base.get_base(); + for i in Self::FILE_PATH{ + base_path = base_path.join(i); + } + base_path + } + + fn save(&self,base:&Self::AcceptStorePoint) -> anyhow::Result<()>; + fn load(base:&Self::AcceptStorePoint) -> anyhow::Result; +} + +pub trait Save:ExpandStorePoint+Serialize{ + + /// The type of the base path you have to accept. + type AcceptStorePoint:BaseStorePoint; + + fn save(&self, save:Self::AcceptStorePoint) -> anyhow::Result<()>; +} + +pub trait Load<'a>:ExpandStorePoint+Deserialize<'a>{ + + /// The type of the base path you have to accept. + type AcceptStorePoint:BaseStorePoint; + + fn load>(base:Self::AcceptStorePoint,suffix:P) -> anyhow::Result<()>; +} \ No newline at end of file From d9af1f548262b914c2f71e9b5a7d525e32b5cbf8 Mon Sep 17 00:00:00 2001 From: bloodnighttw Date: Sat, 13 Jul 2024 21:56:07 +0800 Subject: [PATCH 3/9] Add Macros and Tests --- reginleif-macro/src/lib.rs | 149 +++++++++++++++++++++++++- reginleif-test/src/utils/save_path.rs | 66 +++++------- reginleif-utils/src/save_path.rs | 16 +-- 3 files changed, 186 insertions(+), 45 deletions(-) diff --git a/reginleif-macro/src/lib.rs b/reginleif-macro/src/lib.rs index 881cc03..2852197 100644 --- a/reginleif-macro/src/lib.rs +++ b/reginleif-macro/src/lib.rs @@ -1,5 +1,5 @@ use proc_macro::TokenStream; -use syn::ItemStruct; +use syn::{DeriveInput, ItemStruct, Meta}; fn impl_expire(ast:ItemStruct) -> TokenStream{ let ident = ast.ident; @@ -52,3 +52,150 @@ pub fn refresh_panic(item:TokenStream) -> TokenStream{ token.into() } + +#[proc_macro_derive(BaseStorePoint)] +pub fn base_store_point(item:TokenStream) -> TokenStream{ + let ast:ItemStruct = syn::parse(item).unwrap(); + let ident = ast.ident; + let token = quote::quote! { + impl reginleif_utils::save_path::BaseStorePoint for #ident{ + fn get_base(&self) -> std::path::PathBuf { + self.0.clone() + } + } + }; + + token.into() +} + +fn impl_storage(ast:DeriveInput) -> TokenStream{ + let ident = ast.ident; + let attr1 = ast.attrs.iter().filter( + |x| x.path().is_ident("base_on") + ).nth(0).expect("required #[base_on(BaseStorePoint)] to use this derive!"); + + let attr1 = match &attr1.meta { + Meta::List(a) => a.tokens.clone(), + _o=> panic!("error while parsing argument!") + }; + + let attr2 = ast.attrs.iter().filter( + |x| x.path().is_ident("filepath") + ).nth(0).expect("required #[filepath(&'static [&static str])] to use this derive!"); + + let attr2 = match &attr2.meta { + Meta::List(a) => a.tokens.clone(), + _o=> panic!("error while parsing argument!") + }; + + let token = quote::quote! { + impl reginleif_utils::save_path::Store<'_> for #ident{ + const FILE_PATH: &'static [&'static str] = #attr2; + type AcceptStorePoint = #attr1; + type SelfType = Self; + + fn save(&self, base: &Self::AcceptStorePoint) -> anyhow::Result<()> { + let base_path = Self::full_path(&base); + + std::fs::create_dir_all(base_path.parent().ok_or(anyhow::anyhow!("No parent"))?)?; + std::fs::write(base_path,serde_json::to_string(self)?.as_bytes())?; + + Ok(()) + + } + + fn load(base: &Self::AcceptStorePoint) -> anyhow::Result { + + let base_path = Self::full_path(&base); + + let json = std::fs::read_to_string(base_path)?; + Ok(serde_json::from_str(&json)?) + } + + } + }; + + token.into() +} + +#[proc_macro_derive(Storage, attributes(base_on,filepath))] +pub fn storage(item: TokenStream) -> TokenStream { + let ast:DeriveInput = syn::parse(item).unwrap(); + let implement = impl_storage(ast); + implement +} + +fn impl_save(ast: DeriveInput) -> TokenStream{ + let ident = ast.ident; + let attr1 = ast.attrs.iter().filter( + |x| x.path().is_ident("base_on") + ).nth(0).expect("required #[base_on(BaseStorePoint)] to use this derive!"); + + let attr1 = match &attr1.meta { + Meta::List(a) => a.tokens.clone(), + _o=> panic!("error while parsing argument!") + }; + + let token = quote::quote! { + impl reginleif_utils::save_path::Save for #ident{ + type AcceptStorePoint = #attr1; + + fn save(&self, base: &Self::AcceptStorePoint) -> anyhow::Result<()> { + + let base_path = base.get_base().join(&self.get_suffix()); + + std::fs::create_dir_all(base_path.parent().ok_or(anyhow::anyhow!("No parent"))?)?; + std::fs::write(base_path,serde_json::to_string(self)?.as_bytes())?; + + Ok(()) + } + } + }; + + token.into() + +} + +#[proc_macro_derive(Save, attributes(base_on))] +pub fn save(item: TokenStream) -> TokenStream { + let ast:DeriveInput = syn::parse(item).unwrap(); + let implement = impl_save(ast); + implement +} + +fn impl_load(ast: DeriveInput) -> TokenStream{ + let ident = ast.ident; + let attr1 = ast.attrs.iter().filter( + |x| x.path().is_ident("base_on") + ).nth(0).expect("required #[base_on(BaseStorePoint)] to use this derive!"); + + let attr1 = match &attr1.meta { + Meta::List(a) => a.tokens.clone(), + _o=> panic!("error while parsing argument!") + }; + + let token = quote::quote! { + impl reginleif_utils::save_path::Load<'_> for #ident{ + type AcceptStorePoint = #attr1; + type SelfType = Self; + + fn load>(base: &Self::AcceptStorePoint,suffix:P) -> anyhow::Result{ + let path = base.get_base().join(suffix); + let content = std::fs::read_to_string(path)?; + let json = serde_json::from_str::(&content)?; + Ok(json) + } + } + }; + + token.into() + +} + + +#[proc_macro_derive(Load, attributes(base_on))] +pub fn load(item: TokenStream) -> TokenStream { + let ast:DeriveInput = syn::parse(item).unwrap(); + let implement = impl_load(ast); + implement +} \ No newline at end of file diff --git a/reginleif-test/src/utils/save_path.rs b/reginleif-test/src/utils/save_path.rs index 8fbc54c..803bbcc 100644 --- a/reginleif-test/src/utils/save_path.rs +++ b/reginleif-test/src/utils/save_path.rs @@ -1,64 +1,56 @@ +#[cfg(test)] mod test{ - use std::path::PathBuf; + use std::path::{Path, PathBuf}; use serde::{Deserialize, Serialize}; - use reginleif_utils::save_path::{BaseStorePoint, Store}; + use reginleif_macro::{BaseStorePoint, Load, Save, Storage}; + use reginleif_utils::save_path::{BaseStorePoint, ExpandStorePoint, Load, Save, Store}; - const TEST_PATH_CONST:&'static[&'static str] = &["test"]; + #[derive(BaseStorePoint)] struct TestPath(PathBuf); - impl BaseStorePoint for TestPath{ - fn get_base(&self) -> PathBuf { - self.0.clone() - } - } - impl From for TestPath{ fn from(path:PathBuf) -> Self{ Self(path) } } - #[derive(Deserialize,Serialize,PartialEq,Debug)] + #[derive(Deserialize,Serialize,PartialEq,Debug,Storage)] + #[base_on(TestPath)] #[filepath(&["test.txt"])] struct A; - impl Store<'_> for A{ - const FILE_PATH: &'static [&'static str] = TEST_PATH_CONST; - type AcceptStorePoint = TestPath; - type SelfType = Self; - - fn save(&self, base: &Self::AcceptStorePoint) -> anyhow::Result<()> { - let base_path = Self::full_path(&base); - - std::fs::create_dir_all(base_path.parent().ok_or(anyhow::anyhow!("No parent"))?)?; - std::fs::write(base_path,serde_json::to_string(self)?.as_bytes())?; - - Ok(()) - - } + #[tokio::test] + async fn test_static_save_load(){ + let path = PathBuf::from("test"); + let test_path = TestPath::from(path.clone()); + let a = A; + a.save(&test_path).unwrap(); + let b = A::load(&test_path).unwrap(); + assert_eq!(a,b); - fn load(base: &Self::AcceptStorePoint) -> anyhow::Result { + tokio::fs::remove_dir_all(path).await.unwrap(); + } - let base_path = Self::full_path(&base); + #[derive(Serialize,Deserialize,Save,Load,PartialEq,Debug)] + #[base_on(TestPath)] + struct B; - let json = std::fs::read_to_string(base_path)?; - Ok(serde_json::from_str(&json)?) + impl ExpandStorePoint for B{ + fn get_suffix(&self) -> PathBuf { + PathBuf::from("test223.txt") } - } #[tokio::test] - async fn test_save_load(){ + async fn test_dynamic_save_load(){ let path = PathBuf::from("test"); let test_path = TestPath::from(path.clone()); - let a = A; - a.save(&test_path).unwrap(); - let b = A::load(&test_path).unwrap(); - assert_eq!(a,b); - - tokio::fs::remove_file(path).await.unwrap(); - } + let b = B; + b.save(&test_path).unwrap(); + let temp = B::load(&test_path,"test223.txt").unwrap(); + assert_eq!(b,temp); + } } \ No newline at end of file diff --git a/reginleif-utils/src/save_path.rs b/reginleif-utils/src/save_path.rs index 1a259c4..84c2fba 100644 --- a/reginleif-utils/src/save_path.rs +++ b/reginleif-utils/src/save_path.rs @@ -1,6 +1,7 @@ use std::path::{Path, PathBuf}; use serde::{Deserialize, Serialize}; + pub trait BaseStorePoint:Sync+Send{ /// Get the path of the data. fn get_base(&self) -> PathBuf; @@ -15,7 +16,7 @@ pub trait Store<'a>:Serialize+Deserialize<'a>{ const FILE_PATH:&'static [&'static str]; /// The type of the base path you have to accept. type AcceptStorePoint:BaseStorePoint; - /// You should assign Self to this. + /// You should assign Self to this. type SelfType; fn full_path(base:&Self::AcceptStorePoint) -> PathBuf{ @@ -25,7 +26,7 @@ pub trait Store<'a>:Serialize+Deserialize<'a>{ } base_path } - + fn save(&self,base:&Self::AcceptStorePoint) -> anyhow::Result<()>; fn load(base:&Self::AcceptStorePoint) -> anyhow::Result; } @@ -34,14 +35,15 @@ pub trait Save:ExpandStorePoint+Serialize{ /// The type of the base path you have to accept. type AcceptStorePoint:BaseStorePoint; - - fn save(&self, save:Self::AcceptStorePoint) -> anyhow::Result<()>; + + fn save(&self, save:&Self::AcceptStorePoint) -> anyhow::Result<()>; } -pub trait Load<'a>:ExpandStorePoint+Deserialize<'a>{ +pub trait Load<'a>:Deserialize<'a>{ /// The type of the base path you have to accept. type AcceptStorePoint:BaseStorePoint; - - fn load>(base:Self::AcceptStorePoint,suffix:P) -> anyhow::Result<()>; + type SelfType; + + fn load>(base:&Self::AcceptStorePoint,suffix:P) -> anyhow::Result; } \ No newline at end of file From 28ac19e8e493dbc86af4a2608e9a50e1a8cbf7ef Mon Sep 17 00:00:00 2001 From: bloodnighttw Date: Sat, 13 Jul 2024 22:45:08 +0800 Subject: [PATCH 4/9] Move macros part to trait default part. --- reginleif-macro/src/lib.rs | 17 ----------------- reginleif-test/src/utils/save_path.rs | 5 ++--- reginleif-utils/src/save_path.rs | 25 +++++++++++++++++++------ 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/reginleif-macro/src/lib.rs b/reginleif-macro/src/lib.rs index 2852197..b6eb364 100644 --- a/reginleif-macro/src/lib.rs +++ b/reginleif-macro/src/lib.rs @@ -139,16 +139,6 @@ fn impl_save(ast: DeriveInput) -> TokenStream{ let token = quote::quote! { impl reginleif_utils::save_path::Save for #ident{ type AcceptStorePoint = #attr1; - - fn save(&self, base: &Self::AcceptStorePoint) -> anyhow::Result<()> { - - let base_path = base.get_base().join(&self.get_suffix()); - - std::fs::create_dir_all(base_path.parent().ok_or(anyhow::anyhow!("No parent"))?)?; - std::fs::write(base_path,serde_json::to_string(self)?.as_bytes())?; - - Ok(()) - } } }; @@ -178,13 +168,6 @@ fn impl_load(ast: DeriveInput) -> TokenStream{ impl reginleif_utils::save_path::Load<'_> for #ident{ type AcceptStorePoint = #attr1; type SelfType = Self; - - fn load>(base: &Self::AcceptStorePoint,suffix:P) -> anyhow::Result{ - let path = base.get_base().join(suffix); - let content = std::fs::read_to_string(path)?; - let json = serde_json::from_str::(&content)?; - Ok(json) - } } }; diff --git a/reginleif-test/src/utils/save_path.rs b/reginleif-test/src/utils/save_path.rs index 803bbcc..1b8bd89 100644 --- a/reginleif-test/src/utils/save_path.rs +++ b/reginleif-test/src/utils/save_path.rs @@ -1,9 +1,9 @@ #[cfg(test)] mod test{ - use std::path::{Path, PathBuf}; + use std::path::{PathBuf}; use serde::{Deserialize, Serialize}; use reginleif_macro::{BaseStorePoint, Load, Save, Storage}; - use reginleif_utils::save_path::{BaseStorePoint, ExpandStorePoint, Load, Save, Store}; + use reginleif_utils::save_path::{ExpandStorePoint, Load, Save, Store}; #[derive(BaseStorePoint)] @@ -50,7 +50,6 @@ mod test{ let temp = B::load(&test_path,"test223.txt").unwrap(); assert_eq!(b,temp); - } } \ No newline at end of file diff --git a/reginleif-utils/src/save_path.rs b/reginleif-utils/src/save_path.rs index 84c2fba..624c4a2 100644 --- a/reginleif-utils/src/save_path.rs +++ b/reginleif-utils/src/save_path.rs @@ -1,6 +1,6 @@ use std::path::{Path, PathBuf}; use serde::{Deserialize, Serialize}; - +use serde::de::DeserializeOwned; pub trait BaseStorePoint:Sync+Send{ /// Get the path of the data. @@ -36,14 +36,27 @@ pub trait Save:ExpandStorePoint+Serialize{ /// The type of the base path you have to accept. type AcceptStorePoint:BaseStorePoint; - fn save(&self, save:&Self::AcceptStorePoint) -> anyhow::Result<()>; + fn save(&self, base:&Self::AcceptStorePoint) -> anyhow::Result<()>{ + let base_path = base.get_base().join(&self.get_suffix()); + + std::fs::create_dir_all(base_path.parent().ok_or(anyhow::anyhow!("No parent"))?)?; + std::fs::write(base_path,serde_json::to_string(self)?.as_bytes())?; + + Ok(()) + } } -pub trait Load<'a>:Deserialize<'a>{ +pub trait Load<'a>:DeserializeOwned{ /// The type of the base path you have to accept. type AcceptStorePoint:BaseStorePoint; - type SelfType; - - fn load>(base:&Self::AcceptStorePoint,suffix:P) -> anyhow::Result; + type SelfType:DeserializeOwned; + + fn load>(base: &Self::AcceptStorePoint, suffix: P) -> anyhow::Result{ + let path = base.get_base().join(suffix); + let content = std::fs::read_to_string(path)?; + // Remove the explicit lifetime annotation from the call to `serde_json::from_str` + let json = serde_json::from_str::(&content)?; + Ok(json) + } } \ No newline at end of file From 12753f1efdd774c9e2903044246ef0ae4c253d4b Mon Sep 17 00:00:00 2001 From: bloodnighttw Date: Sat, 13 Jul 2024 22:52:48 +0800 Subject: [PATCH 5/9] Move macros part to trait default part. --- reginleif-macro/src/lib.rs | 23 ++--------------------- reginleif-utils/src/save_path.rs | 25 ++++++++++++++++++++----- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/reginleif-macro/src/lib.rs b/reginleif-macro/src/lib.rs index b6eb364..8125db7 100644 --- a/reginleif-macro/src/lib.rs +++ b/reginleif-macro/src/lib.rs @@ -89,29 +89,10 @@ fn impl_storage(ast:DeriveInput) -> TokenStream{ }; let token = quote::quote! { - impl reginleif_utils::save_path::Store<'_> for #ident{ + impl reginleif_utils::save_path::Store for #ident{ const FILE_PATH: &'static [&'static str] = #attr2; type AcceptStorePoint = #attr1; type SelfType = Self; - - fn save(&self, base: &Self::AcceptStorePoint) -> anyhow::Result<()> { - let base_path = Self::full_path(&base); - - std::fs::create_dir_all(base_path.parent().ok_or(anyhow::anyhow!("No parent"))?)?; - std::fs::write(base_path,serde_json::to_string(self)?.as_bytes())?; - - Ok(()) - - } - - fn load(base: &Self::AcceptStorePoint) -> anyhow::Result { - - let base_path = Self::full_path(&base); - - let json = std::fs::read_to_string(base_path)?; - Ok(serde_json::from_str(&json)?) - } - } }; @@ -165,7 +146,7 @@ fn impl_load(ast: DeriveInput) -> TokenStream{ }; let token = quote::quote! { - impl reginleif_utils::save_path::Load<'_> for #ident{ + impl reginleif_utils::save_path::Load for #ident{ type AcceptStorePoint = #attr1; type SelfType = Self; } diff --git a/reginleif-utils/src/save_path.rs b/reginleif-utils/src/save_path.rs index 624c4a2..b967352 100644 --- a/reginleif-utils/src/save_path.rs +++ b/reginleif-utils/src/save_path.rs @@ -1,5 +1,5 @@ use std::path::{Path, PathBuf}; -use serde::{Deserialize, Serialize}; +use serde::{Serialize}; use serde::de::DeserializeOwned; pub trait BaseStorePoint:Sync+Send{ @@ -11,7 +11,7 @@ pub trait ExpandStorePoint{ fn get_suffix(&self) -> PathBuf; } -pub trait Store<'a>:Serialize+Deserialize<'a>{ +pub trait Store:Serialize+DeserializeOwned{ const FILE_PATH:&'static [&'static str]; /// The type of the base path you have to accept. @@ -27,8 +27,23 @@ pub trait Store<'a>:Serialize+Deserialize<'a>{ base_path } - fn save(&self,base:&Self::AcceptStorePoint) -> anyhow::Result<()>; - fn load(base:&Self::AcceptStorePoint) -> anyhow::Result; + fn save(&self, base: &Self::AcceptStorePoint) -> anyhow::Result<()> { + let base_path = Self::full_path(&base); + + std::fs::create_dir_all(base_path.parent().ok_or(anyhow::anyhow!("No parent"))?)?; + std::fs::write(base_path,serde_json::to_string(self)?.as_bytes())?; + + Ok(()) + + } + + fn load(base: &Self::AcceptStorePoint) -> anyhow::Result { + + let base_path = Self::full_path(&base); + + let json = std::fs::read_to_string(base_path)?; + Ok(serde_json::from_str(&json)?) + } } pub trait Save:ExpandStorePoint+Serialize{ @@ -46,7 +61,7 @@ pub trait Save:ExpandStorePoint+Serialize{ } } -pub trait Load<'a>:DeserializeOwned{ +pub trait Load:DeserializeOwned{ /// The type of the base path you have to accept. type AcceptStorePoint:BaseStorePoint; From b309e3a664725e8c193bc296f2e2e17b68b1576c Mon Sep 17 00:00:00 2001 From: bloodnighttw Date: Sun, 14 Jul 2024 00:54:54 +0800 Subject: [PATCH 6/9] Make macro support generic type. --- reginleif-macro/src/lib.rs | 127 +++++++++++++++++--------- reginleif-test/src/utils/save_path.rs | 71 +++++++++++++- 2 files changed, 150 insertions(+), 48 deletions(-) diff --git a/reginleif-macro/src/lib.rs b/reginleif-macro/src/lib.rs index 8125db7..d33ea64 100644 --- a/reginleif-macro/src/lib.rs +++ b/reginleif-macro/src/lib.rs @@ -70,33 +70,48 @@ pub fn base_store_point(item:TokenStream) -> TokenStream{ fn impl_storage(ast:DeriveInput) -> TokenStream{ let ident = ast.ident; - let attr1 = ast.attrs.iter().filter( - |x| x.path().is_ident("base_on") - ).nth(0).expect("required #[base_on(BaseStorePoint)] to use this derive!"); - - let attr1 = match &attr1.meta { - Meta::List(a) => a.tokens.clone(), - _o=> panic!("error while parsing argument!") - }; - let attr2 = ast.attrs.iter().filter( + let filepath = ast.attrs.iter().filter( |x| x.path().is_ident("filepath") ).nth(0).expect("required #[filepath(&'static [&static str])] to use this derive!"); - let attr2 = match &attr2.meta { + let filepath = match &filepath.meta { Meta::List(a) => a.tokens.clone(), _o=> panic!("error while parsing argument!") }; - let token = quote::quote! { - impl reginleif_utils::save_path::Store for #ident{ - const FILE_PATH: &'static [&'static str] = #attr2; - type AcceptStorePoint = #attr1; - type SelfType = Self; - } - }; + let base_on = ast.attrs.iter().filter( + |x| x.path().is_ident("base_on") + ).nth(0); + + return if let Some(base_on) = base_on { + let base_on = match &base_on.meta { + Meta::List(a) => a.tokens.clone(), + _o=> panic!("error while parsing argument!") + }; + + + let token = quote::quote! { + impl reginleif_utils::save_path::Store for #ident{ + const FILE_PATH: &'static [&'static str] = #filepath; + type AcceptStorePoint = #base_on; + type SelfType = Self; + } + }; + token.into() + }else{ // this mean we are declared a generic struct. + let token = quote::quote! { + impl reginleif_utils::save_path::Store for #ident + where T: reginleif_utils::save_path::BaseStorePoint{ + const FILE_PATH: &'static [&'static str] = #filepath; + type AcceptStorePoint = T; + type SelfType = Self; + } + }; + token.into() + + } - token.into() } #[proc_macro_derive(Storage, attributes(base_on,filepath))] @@ -108,22 +123,33 @@ pub fn storage(item: TokenStream) -> TokenStream { fn impl_save(ast: DeriveInput) -> TokenStream{ let ident = ast.ident; - let attr1 = ast.attrs.iter().filter( + let base_on = ast.attrs.iter().filter( |x| x.path().is_ident("base_on") - ).nth(0).expect("required #[base_on(BaseStorePoint)] to use this derive!"); + ).nth(0); - let attr1 = match &attr1.meta { - Meta::List(a) => a.tokens.clone(), - _o=> panic!("error while parsing argument!") - }; + if let Some(base_on) = base_on { + let base_on = match &base_on.meta { + Meta::List(a) => a.tokens.clone(), + _o=> panic!("error while parsing argument!") + }; - let token = quote::quote! { - impl reginleif_utils::save_path::Save for #ident{ - type AcceptStorePoint = #attr1; - } - }; + let token = quote::quote! { + impl reginleif_utils::save_path::Save for #ident{ + type AcceptStorePoint = #base_on; + } + }; + + token.into() + } else { // this mean we are declared a generic struct. + let token = quote::quote! { + impl reginleif_utils::save_path::Save for #ident + where T: reginleif_utils::save_path::BaseStorePoint{ + type AcceptStorePoint = T; + } + }; - token.into() + token.into() + } } @@ -136,23 +162,36 @@ pub fn save(item: TokenStream) -> TokenStream { fn impl_load(ast: DeriveInput) -> TokenStream{ let ident = ast.ident; - let attr1 = ast.attrs.iter().filter( + let base_on = ast.attrs.iter().filter( |x| x.path().is_ident("base_on") - ).nth(0).expect("required #[base_on(BaseStorePoint)] to use this derive!"); - - let attr1 = match &attr1.meta { - Meta::List(a) => a.tokens.clone(), - _o=> panic!("error while parsing argument!") - }; + ).nth(0); + + if let Some(base_on) = base_on { + let base_on = match &base_on.meta { + Meta::List(a) => a.tokens.clone(), + _o=> panic!("error while parsing argument!") + }; + + let token = quote::quote! { + impl reginleif_utils::save_path::Load for #ident{ + type AcceptStorePoint = #base_on; + type SelfType = Self; + } + }; + + token.into() + } else { // this mean we are declared a generic struct. + let token = quote::quote! { + impl reginleif_utils::save_path::Load for #ident + where T: reginleif_utils::save_path::BaseStorePoint{ + type AcceptStorePoint = T; + type SelfType = Self; + } + }; - let token = quote::quote! { - impl reginleif_utils::save_path::Load for #ident{ - type AcceptStorePoint = #attr1; - type SelfType = Self; - } - }; + token.into() - token.into() + } } diff --git a/reginleif-test/src/utils/save_path.rs b/reginleif-test/src/utils/save_path.rs index 1b8bd89..b88318f 100644 --- a/reginleif-test/src/utils/save_path.rs +++ b/reginleif-test/src/utils/save_path.rs @@ -1,12 +1,13 @@ #[cfg(test)] mod test{ + use std::marker::PhantomData; use std::path::{PathBuf}; use serde::{Deserialize, Serialize}; use reginleif_macro::{BaseStorePoint, Load, Save, Storage}; - use reginleif_utils::save_path::{ExpandStorePoint, Load, Save, Store}; + use reginleif_utils::save_path::{BaseStorePoint, ExpandStorePoint, Load, Save, Store}; - #[derive(BaseStorePoint)] + #[derive(BaseStorePoint,PartialEq,Debug)] struct TestPath(PathBuf); impl From for TestPath{ @@ -21,7 +22,7 @@ mod test{ #[tokio::test] async fn test_static_save_load(){ - let path = PathBuf::from("test"); + let path = PathBuf::from("test1"); let test_path = TestPath::from(path.clone()); let a = A; a.save(&test_path).unwrap(); @@ -43,13 +44,75 @@ mod test{ #[tokio::test] async fn test_dynamic_save_load(){ - let path = PathBuf::from("test"); + let path = PathBuf::from("test2"); let test_path = TestPath::from(path.clone()); let b = B; b.save(&test_path).unwrap(); let temp = B::load(&test_path,"test223.txt").unwrap(); assert_eq!(b,temp); + + tokio::fs::remove_dir_all(path).await.unwrap(); + + } + + #[derive(Serialize,Deserialize,PartialEq,Debug)] + struct C where T:BaseStorePoint{ + num:String, + _t:PhantomData + } + + impl ExpandStorePoint for C where T:BaseStorePoint{ + fn get_suffix(&self) -> PathBuf { + PathBuf::from(&format!("{}.txt",&self.num)) + } + } + + impl Save for C where T:BaseStorePoint{ + type AcceptStorePoint = T; + } + + impl Load for C where T:BaseStorePoint{ + type AcceptStorePoint = T; + type SelfType = Self; + } + + type D = C; + + impl From for D{ + fn from(value: String) -> Self { + Self{ + num: value, + _t: Default::default(), + } + } + } + + #[tokio::test] + async fn generic_test(){ + let path = PathBuf::from("test3"); + let test_path = TestPath::from(path.clone()); + let d:D = String::from("123").into(); + d.save(&test_path).unwrap(); + + let temp = D::load(&test_path,"123.txt").unwrap(); + assert_eq!(d,temp); + + tokio::fs::remove_dir_all(path).await.unwrap(); } + + #[derive(Serialize,Deserialize,PartialEq,Debug,Save,Load)] + struct E where T:BaseStorePoint{ + num:String, + _t:PhantomData + } + + impl ExpandStorePoint for E where T:BaseStorePoint{ + fn get_suffix(&self) -> PathBuf { + PathBuf::from(&format!("{}.txt",&self.num)) + } + } + + } \ No newline at end of file From 8cd796c02f274db06649118922dfd8e14cdc74b6 Mon Sep 17 00:00:00 2001 From: bloodnighttw Date: Sun, 14 Jul 2024 02:24:14 +0800 Subject: [PATCH 7/9] Add document to file. --- reginleif-macro/src/lib.rs | 4 - reginleif-test/src/utils/save_path.rs | 1 - reginleif-utils/src/save_path.rs | 255 +++++++++++++++++++++++++- 3 files changed, 250 insertions(+), 10 deletions(-) diff --git a/reginleif-macro/src/lib.rs b/reginleif-macro/src/lib.rs index d33ea64..1d445ae 100644 --- a/reginleif-macro/src/lib.rs +++ b/reginleif-macro/src/lib.rs @@ -95,7 +95,6 @@ fn impl_storage(ast:DeriveInput) -> TokenStream{ impl reginleif_utils::save_path::Store for #ident{ const FILE_PATH: &'static [&'static str] = #filepath; type AcceptStorePoint = #base_on; - type SelfType = Self; } }; token.into() @@ -105,7 +104,6 @@ fn impl_storage(ast:DeriveInput) -> TokenStream{ where T: reginleif_utils::save_path::BaseStorePoint{ const FILE_PATH: &'static [&'static str] = #filepath; type AcceptStorePoint = T; - type SelfType = Self; } }; token.into() @@ -175,7 +173,6 @@ fn impl_load(ast: DeriveInput) -> TokenStream{ let token = quote::quote! { impl reginleif_utils::save_path::Load for #ident{ type AcceptStorePoint = #base_on; - type SelfType = Self; } }; @@ -185,7 +182,6 @@ fn impl_load(ast: DeriveInput) -> TokenStream{ impl reginleif_utils::save_path::Load for #ident where T: reginleif_utils::save_path::BaseStorePoint{ type AcceptStorePoint = T; - type SelfType = Self; } }; diff --git a/reginleif-test/src/utils/save_path.rs b/reginleif-test/src/utils/save_path.rs index b88318f..6d70da2 100644 --- a/reginleif-test/src/utils/save_path.rs +++ b/reginleif-test/src/utils/save_path.rs @@ -74,7 +74,6 @@ mod test{ impl Load for C where T:BaseStorePoint{ type AcceptStorePoint = T; - type SelfType = Self; } type D = C; diff --git a/reginleif-utils/src/save_path.rs b/reginleif-utils/src/save_path.rs index b967352..8a54fe6 100644 --- a/reginleif-utils/src/save_path.rs +++ b/reginleif-utils/src/save_path.rs @@ -1,24 +1,131 @@ +//! The module for the save and load the data from the file. +//! It provides the trait to save and load the data from the file, +//! from the path that is constant to dynamic. use std::path::{Path, PathBuf}; use serde::{Serialize}; use serde::de::DeserializeOwned; +/// A trait for the base path of the data. +/// +/// You have to implement this trait to provide the base path of the data. +/// You also have to care about the thread safety of the data. +/// The data should be thread safe (Sync+Send). +/// +/// You can use the derive macro to implement this trait. +/// You can also implement [From](From) or [TryFrom](TryFrom) +/// to data struct convert more easily. +/// +/// # Example +/// ```no_run +/// use std::path::PathBuf; +/// use reginleif_macro::BaseStorePoint; +/// +/// #[derive(BaseStorePoint)] // the macro only accept one field struct. +/// struct TestPath(PathBuf); +/// +/// ``` pub trait BaseStorePoint:Sync+Send{ /// Get the path of the data. fn get_base(&self) -> PathBuf; } +/// The trait that return the relative path of the data from base. +/// +/// This trait is using by [Save](Save) trait to get the relative path of the data +/// from base, and you have to implement this trait to provide the relative path of the data +/// if you are about to use [Save](Save) trait. +/// It is used by the struct which have a path that is not constant, varies from its field, and +/// if you have a constant path, you should use [Store](Store) trait. +/// +/// # Example +/// ```no_run +/// use std::path::PathBuf; +/// use serde::{Deserialize, Serialize}; +/// use reginleif_macro::{BaseStorePoint, Storage}; +/// use reginleif_utils::save_path::{Store, Save, Load}; +/// +/// #[derive(BaseStorePoint,PartialEq,Debug)] +/// struct TestPath(PathBuf); +/// +/// impl From for TestPath{ +/// fn from(path:PathBuf) -> Self{ +/// Self(path) +/// } +/// } +/// ``` pub trait ExpandStorePoint{ fn get_suffix(&self) -> PathBuf; } +/// A trait for the store of the data which have a const path. +/// +/// You have to implement this trait to provide the store path of the data. +/// When compared to [Save](Save) and [Load](Load) trait, this trait is used for the data which have a constant path. +/// +/// You can also use the derive macro to implement this trait. +/// +/// # Example +/// ```no_run +/// use std::path::PathBuf; +/// use serde::{Deserialize, Serialize}; +/// use reginleif_macro::{BaseStorePoint, Storage}; +/// use reginleif_utils::save_path::{Store, Save, Load}; +/// +/// #[derive(BaseStorePoint,PartialEq,Debug)] +/// struct TestPath(PathBuf); +/// +/// impl From for TestPath{ +/// fn from(path:PathBuf) -> Self{ +/// Self(path) +/// } +/// } +/// +/// #[derive(Deserialize,Serialize,PartialEq,Debug,Storage)] +/// #[base_on(TestPath)] #[filepath(&["test.txt"])] // the file will store in TestPath + test.txt +/// struct A; +/// +/// +/// ``` +/// +/// The macro also support AcceptStorePoint as a generic type, +/// so you can use the generic type to store the data with different base path. +/// +/// # Example +/// ```no_run +/// use std::marker::PhantomData; +/// use std::path::PathBuf; +/// use serde::{Deserialize, Serialize}; +/// use reginleif_macro::{BaseStorePoint, Storage}; +/// use reginleif_utils::save_path::{Store, Save, Load, BaseStorePoint}; +/// +/// #[derive(BaseStorePoint,PartialEq,Debug)] +/// struct TestPath(PathBuf); +/// +/// impl From for TestPath{ +/// fn from(path:PathBuf) -> Self{ +/// Self(path) +/// } +/// } +/// +/// #[derive(Deserialize,Serialize,PartialEq,Debug,Storage)] +/// struct A where T:BaseStorePoint{ +/// num:String, +/// _t:PhantomData +/// } +/// +/// ``` +/// +/// Now you can store the data with different base path with generic type. pub trait Store:Serialize+DeserializeOwned{ + /// The const path of the file. + /// Separate the path by the array of the str. const FILE_PATH:&'static [&'static str]; /// The type of the base path you have to accept. + /// This field will become save and load function's argument. type AcceptStorePoint:BaseStorePoint; - /// You should assign Self to this. - type SelfType; + /// Get the full path of the data. fn full_path(base:&Self::AcceptStorePoint) -> PathBuf{ let mut base_path = base.get_base(); for i in Self::FILE_PATH{ @@ -27,6 +134,10 @@ pub trait Store:Serialize+DeserializeOwned{ base_path } + /// Save the data to the file. + /// + /// # Arguments + /// * `base`: the base path of the data. fn save(&self, base: &Self::AcceptStorePoint) -> anyhow::Result<()> { let base_path = Self::full_path(&base); @@ -37,6 +148,10 @@ pub trait Store:Serialize+DeserializeOwned{ } + /// Load the data from the file. + /// + /// # Arguments + /// * `base`: the base path of the data. fn load(base: &Self::AcceptStorePoint) -> anyhow::Result { let base_path = Self::full_path(&base); @@ -46,11 +161,76 @@ pub trait Store:Serialize+DeserializeOwned{ } } +/// A trait for the save the data which have a dynamic path. +/// +/// You have to implement this trait to save the data to the file. +/// When compared to [Store](Store) trait, this trait is used for the data which have a dynamic path. +/// +/// You can also use the derive macro to implement this trait. +/// +/// # Example +/// ```no_run +/// use std::path::PathBuf; +/// use serde::{Deserialize, Serialize}; +/// use reginleif_macro::{BaseStorePoint, Save, Load}; +/// use reginleif_utils::save_path::{ExpandStorePoint, Save, Load}; +/// +/// #[derive(Serialize,Deserialize,Save,Load,PartialEq,Debug)] +/// #[base_on(TestPath)] +/// struct B(i32); +/// +/// impl ExpandStorePoint for B{ // you should implement this trait to provide the relative path of the data from base. +/// fn get_suffix(&self) -> PathBuf { +/// PathBuf::from(format!("{}.json",self.0)) +/// } +/// } +/// ``` +/// +/// The macro also support AcceptStorePoint as a generic type, +/// so you can use the generic type to save the data with different base path. +/// Note the generic argument should be the struct that impl [BaseStorePoint](BaseStorePoint) trait +/// and only one. +/// +/// # Example +/// ```no_run +/// use std::marker::PhantomData; +/// use std::path::PathBuf; +/// use serde::{Deserialize, Serialize}; +/// use reginleif_macro::{BaseStorePoint, Load, Save, Storage}; +/// use reginleif_utils::save_path::{Store, Save, Load, BaseStorePoint, ExpandStorePoint}; +/// +/// #[derive(BaseStorePoint,PartialEq,Debug)] +/// struct TestPath(PathBuf); +/// +/// impl From for TestPath{ +/// fn from(path:PathBuf) -> Self{ +/// Self(path) +/// } +/// } +/// +/// #[derive(Serialize,Deserialize,PartialEq,Debug,Save,Load)] +/// struct C where T:BaseStorePoint{ +/// num:String, +/// _t:PhantomData +/// } +/// +/// impl ExpandStorePoint for C where T:BaseStorePoint{ // you still need to implement this trait to provide the relative path of the data from base. +/// fn get_suffix(&self) -> PathBuf { +/// PathBuf::from(format!("{}.json",self.num)) +/// } +/// } +/// +/// ``` pub trait Save:ExpandStorePoint+Serialize{ /// The type of the base path you have to accept. + /// This field will become save function's argument. type AcceptStorePoint:BaseStorePoint; + /// Save the data to the file. + /// + /// # Arguments + /// * `base`: the base path of the data. fn save(&self, base:&Self::AcceptStorePoint) -> anyhow::Result<()>{ let base_path = base.get_base().join(&self.get_suffix()); @@ -61,17 +241,82 @@ pub trait Save:ExpandStorePoint+Serialize{ } } + +/// A trait to load the data which have a dynamic path. +/// +/// You have to implement this trait to load the data from the file. +/// +/// You can also use the derive macro to implement this trait. +/// +/// # Example +/// ```no_run +/// use std::path::PathBuf; +/// use serde::{Deserialize, Serialize}; +/// use reginleif_macro::{BaseStorePoint, Save, Load}; +/// use reginleif_utils::save_path::{ExpandStorePoint, Save, Load}; +/// +/// #[derive(Serialize,Deserialize,Save,Load,PartialEq,Debug)] +/// #[base_on(TestPath)] +/// struct B; +/// +/// impl ExpandStorePoint for B{ // you should implement this trait to provide the relative path of the data from base. +/// fn get_suffix(&self) -> PathBuf { +/// PathBuf::from("test.txt") +/// } +/// } +/// ``` +/// +/// The macro also support AcceptStorePoint as a generic type, +/// so you can use the generic type to save the data with different base path. +/// Note the generic argument should be the struct that impl [BaseStorePoint](BaseStorePoint) trait +/// and only one. +/// +/// # Example +/// ```no_run +/// use std::marker::PhantomData; +/// use std::path::PathBuf; +/// use serde::{Deserialize, Serialize}; +/// use reginleif_macro::{BaseStorePoint, Load, Save, Storage}; +/// use reginleif_utils::save_path::{Store, Save, Load, BaseStorePoint, ExpandStorePoint}; +/// +/// #[derive(BaseStorePoint,PartialEq,Debug)] +/// struct TestPath(PathBuf); +/// +/// impl From for TestPath{ +/// fn from(path:PathBuf) -> Self{ +/// Self(path) +/// } +/// } +/// +/// #[derive(Serialize,Deserialize,PartialEq,Debug,Save,Load)] +/// struct C where T:BaseStorePoint{ +/// num:String, +/// _t:PhantomData +/// } +/// +/// impl ExpandStorePoint for C where T:BaseStorePoint{ // you still need to implement this trait to provide the relative path of the data from base. +/// fn get_suffix(&self) -> PathBuf { +/// PathBuf::from(format!("{}.json",self.num)) +/// } +/// } +/// +/// ``` + pub trait Load:DeserializeOwned{ /// The type of the base path you have to accept. type AcceptStorePoint:BaseStorePoint; - type SelfType:DeserializeOwned; - fn load>(base: &Self::AcceptStorePoint, suffix: P) -> anyhow::Result{ + /// Load the data from the file. + /// + /// # Arguments + /// * `base`: the base path of the data. + /// * `suffix`: the relative path of the data from base. + fn load>(base: &Self::AcceptStorePoint, suffix: P) -> anyhow::Result{ let path = base.get_base().join(suffix); let content = std::fs::read_to_string(path)?; // Remove the explicit lifetime annotation from the call to `serde_json::from_str` - let json = serde_json::from_str::(&content)?; + let json = serde_json::from_str(&content)?; Ok(json) } } \ No newline at end of file From 0ded7d7fc30e4df1459b1264f9b5c69af85405ab Mon Sep 17 00:00:00 2001 From: bloodnighttw Date: Sun, 14 Jul 2024 02:28:46 +0800 Subject: [PATCH 8/9] Fix document error! --- reginleif-utils/src/save_path.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/reginleif-utils/src/save_path.rs b/reginleif-utils/src/save_path.rs index 8a54fe6..e619592 100644 --- a/reginleif-utils/src/save_path.rs +++ b/reginleif-utils/src/save_path.rs @@ -108,6 +108,7 @@ pub trait ExpandStorePoint{ /// } /// /// #[derive(Deserialize,Serialize,PartialEq,Debug,Storage)] +/// #[filepath(&["test.txt"])] /// struct A where T:BaseStorePoint{ /// num:String, /// _t:PhantomData @@ -175,6 +176,15 @@ pub trait Store:Serialize+DeserializeOwned{ /// use reginleif_macro::{BaseStorePoint, Save, Load}; /// use reginleif_utils::save_path::{ExpandStorePoint, Save, Load}; /// +/// #[derive(BaseStorePoint,PartialEq,Debug)] +/// struct TestPath(PathBuf); +/// +/// impl From for TestPath{ +/// fn from(path:PathBuf) -> Self{ +/// Self(path) +/// } +/// } +/// /// #[derive(Serialize,Deserialize,Save,Load,PartialEq,Debug)] /// #[base_on(TestPath)] /// struct B(i32); @@ -255,6 +265,15 @@ pub trait Save:ExpandStorePoint+Serialize{ /// use reginleif_macro::{BaseStorePoint, Save, Load}; /// use reginleif_utils::save_path::{ExpandStorePoint, Save, Load}; /// +/// #[derive(BaseStorePoint,PartialEq,Debug)] +/// struct TestPath(PathBuf); +/// +/// impl From for TestPath{ +/// fn from(path:PathBuf) -> Self{ +/// Self(path) +/// } +/// } +/// /// #[derive(Serialize,Deserialize,Save,Load,PartialEq,Debug)] /// #[base_on(TestPath)] /// struct B; From dff7a5710aff9e5b9f4e93bbd972ca0c840b960c Mon Sep 17 00:00:00 2001 From: bloodnighttw Date: Sun, 14 Jul 2024 02:33:36 +0800 Subject: [PATCH 9/9] Update version tag --- Cargo.lock | 8 ++++---- Cargo.toml | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index abb4c27..cf98cd0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -724,7 +724,7 @@ dependencies = [ [[package]] name = "reginleif" -version = "0.1.3" +version = "0.2.0-alpha-1" dependencies = [ "anyhow", "async-trait", @@ -740,7 +740,7 @@ dependencies = [ [[package]] name = "reginleif-macro" -version = "0.1.3" +version = "0.2.0-alpha-1" dependencies = [ "quote", "syn", @@ -748,7 +748,7 @@ dependencies = [ [[package]] name = "reginleif-test" -version = "0.1.3" +version = "0.2.0-alpha-1" dependencies = [ "anyhow", "async-trait", @@ -763,7 +763,7 @@ dependencies = [ [[package]] name = "reginleif-utils" -version = "0.1.3" +version = "0.2.0-alpha-1" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 5d780e5..7a6cbe8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ members=[ resolver = "2" [workspace.package] -version = "0.1.3" # Don't forget to update this version to dependencies in [workspace.dependencies] reginleif-utils and reginleif-macro +version = "0.2.0-alpha-1" # Don't forget to update this version to dependencies in [workspace.dependencies] reginleif-utils and reginleif-macro license = "Apache-2.0" description = "The core library of nolauncher." readme = "README.md" @@ -23,5 +23,5 @@ tokio = { version = "1.38.0", features = ["full"] } async-trait = "0.1.81" reqwest = { version = "0.12.5", features = ["json"] } thiserror = "1.0.61" -reginleif-utils = {path = "reginleif-utils", version = "0.1.3"} # Same version as workspace -reginleif-macro = {path = "reginleif-macro", version = "0.1.3"} # Same version as workspace +reginleif-utils = {path = "reginleif-utils", version = "0.2.0-alpha-1"} # Same version as workspace +reginleif-macro = {path = "reginleif-macro", version = "0.2.0-alpha-1"} # Same version as workspace