Skip to content

Commit

Permalink
add custom secret impl
Browse files Browse the repository at this point in the history
  • Loading branch information
Chethan-rao committed Sep 19, 2024
1 parent eded347 commit 9a46dd0
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i32>,
// }

// struct Secret<T, Strategy = WithType>
// where
// Strategy: StrategyTrait,
// {
// pub inner_secret: T,
// pub strategy: PhantomData<Strategy>,
// }

// impl<T> Secret<T> {
// fn new(ele: T) -> Self {
// Secret {
// inner_secret: ele,
// strategy: PhantomData,
// }
// }
// }

// impl<T> std::fmt::Debug for Secret<T> {
// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// write!(f, "** {} **", std::any::type_name::<T>())
// }
// }

// trait StrategyTrait {}

// pub enum WithType {}

// impl StrategyTrait for WithType {}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

// 54. PhantomData usecase

// #[derive(Debug)]
// struct MyType<T = EncryptedState>
// where
// T: SecuredState,
// {
// field: i32,
// type1: std::marker::PhantomData<T>,
// }

// impl<T> MyType<T>
// 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() {}

0 comments on commit 9a46dd0

Please sign in to comment.