From 9a46dd0abac14d69c9a116ec05fa98d845d301c4 Mon Sep 17 00:00:00 2001 From: Chethan Date: Thu, 19 Sep 2024 16:31:03 +0530 Subject: [PATCH] add custom secret impl --- src/main.rs | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/src/main.rs b/src/main.rs index b012ddc..df03cf8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2380,4 +2380,95 @@ ///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// 53. Custom Secret impl + +// use std::marker::PhantomData; + +// fn main() { +// let a = Example { a: Secret::new(4) }; + +// println!("{a:?}"); +// } + +// #[derive(Debug)] +// struct Example { +// a: Secret, +// } + +// struct Secret +// where +// Strategy: StrategyTrait, +// { +// pub inner_secret: T, +// pub strategy: PhantomData, +// } + +// impl Secret { +// fn new(ele: T) -> Self { +// Secret { +// inner_secret: ele, +// strategy: PhantomData, +// } +// } +// } + +// impl std::fmt::Debug for Secret { +// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +// write!(f, "** {} **", std::any::type_name::()) +// } +// } + +// trait StrategyTrait {} + +// pub enum WithType {} + +// impl StrategyTrait for WithType {} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// + +// 54. PhantomData usecase + +// #[derive(Debug)] +// struct MyType +// where +// T: SecuredState, +// { +// field: i32, +// type1: std::marker::PhantomData, +// } + +// impl MyType +// where +// T: SecuredState, +// { +// fn new(field: i32) -> Self { +// Self { +// field, +// type1: std::marker::PhantomData, +// } +// } +// } + +// trait SecuredState {} + +// #[derive(Debug)] +// struct RawState; + +// #[derive(Debug)] +// struct EncryptedState; + +// impl SecuredState for RawState {} + +// impl SecuredState for EncryptedState {} + +// fn main() { +// let mytype1: MyType = MyType::new(45); + +// println!("{mytype1:?}"); +// } + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// + +// 55. + fn main() {}