feat: constructors for util adapters

This commit is contained in:
Aravinth Manivannan 2025-01-09 01:05:57 +05:30
parent 52ea8be4d7
commit 7bb8dff35e
Signed by: realaravinth
GPG key ID: F8F50389936984FF
3 changed files with 12 additions and 6 deletions

View file

@ -32,10 +32,12 @@ impl GenerateRandomNumberInterface for GenerateRandomNumber {
} }
impl GenerateRandomNumber { impl GenerateRandomNumber {
pub fn new() -> GenerateRandomNumberInterfaceObj {
Arc::new(GenerateRandomNumber)
}
pub fn inject() -> impl FnOnce(&mut web::ServiceConfig) { pub fn inject() -> impl FnOnce(&mut web::ServiceConfig) {
let g = WebGenerateRandomNumberInterfaceObj::new(Arc::new(GenerateRandomNumber));
let f = move |cfg: &mut web::ServiceConfig| { let f = move |cfg: &mut web::ServiceConfig| {
cfg.app_data(g); cfg.app_data(WebGenerateRandomNumberInterfaceObj::new(Self::new()));
}; };
Box::new(f) Box::new(f)

View file

@ -37,10 +37,12 @@ impl GenerateRandomStringInterface for GenerateRandomString {
} }
impl GenerateRandomString { impl GenerateRandomString {
pub fn new() -> GenerateRandomStringInterfaceObj {
Arc::new(GenerateRandomString)
}
pub fn inject() -> impl FnOnce(&mut web::ServiceConfig) { pub fn inject() -> impl FnOnce(&mut web::ServiceConfig) {
let g = WebGenerateRandomStringInterfaceObj::new(Arc::new(GenerateRandomString));
let f = move |cfg: &mut web::ServiceConfig| { let f = move |cfg: &mut web::ServiceConfig| {
cfg.app_data(g); cfg.app_data(WebGenerateRandomStringInterfaceObj::new(Self::new()));
}; };
Box::new(f) Box::new(f)

View file

@ -28,10 +28,12 @@ impl GetUUID for GenerateUUID {
} }
impl GenerateUUID { impl GenerateUUID {
pub fn new() -> GetUUIDInterfaceObj {
Arc::new(GenerateUUID)
}
pub fn inject() -> impl FnOnce(&mut web::ServiceConfig) { pub fn inject() -> impl FnOnce(&mut web::ServiceConfig) {
let g = WebGetUUIDInterfaceObj::new(Arc::new(GenerateUUID));
let f = move |cfg: &mut web::ServiceConfig| { let f = move |cfg: &mut web::ServiceConfig| {
cfg.app_data(g); cfg.app_data(WebGetUUIDInterfaceObj::new(Self::new()));
}; };
Box::new(f) Box::new(f)