mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	refactor(router): move api models into separate crate (#103)
This commit is contained in:
		
							
								
								
									
										12
									
								
								crates/common_utils/src/consts.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								crates/common_utils/src/consts.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,12 @@ | ||||
| //! Commonly used constants | ||||
|  | ||||
| /// Number of characters in a generated ID | ||||
| pub const ID_LENGTH: usize = 20; | ||||
|  | ||||
| /// Characters to use for generating NanoID | ||||
| pub(crate) const ALPHABETS: [char; 62] = [ | ||||
|     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', | ||||
|     'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', | ||||
|     'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', | ||||
|     'V', 'W', 'X', 'Y', 'Z', | ||||
| ]; | ||||
| @ -13,6 +13,7 @@ | ||||
| )] | ||||
| #![doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR" ), "/", "README.md"))] | ||||
|  | ||||
| pub mod consts; | ||||
| pub mod custom_serde; | ||||
| pub mod errors; | ||||
| pub mod ext_traits; | ||||
| @ -29,3 +30,16 @@ pub mod date_time { | ||||
|         PrimitiveDateTime::new(utc_date_time.date(), utc_date_time.time()) | ||||
|     } | ||||
| } | ||||
|  | ||||
| /// Generate a nanoid with the given prefix and length | ||||
| #[inline] | ||||
| pub fn generate_id(length: usize, prefix: &str) -> String { | ||||
|     format!("{}_{}", prefix, nanoid::nanoid!(length, &consts::ALPHABETS)) | ||||
| } | ||||
|  | ||||
| /// Generate a nanoid with the given prefix and a default length | ||||
| #[inline] | ||||
| pub fn generate_id_with_default_len(prefix: &str) -> String { | ||||
|     let len = consts::ID_LENGTH; | ||||
|     format!("{}_{}", prefix, nanoid::nanoid!(len, &consts::ALPHABETS)) | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 ItsMeShashank
					ItsMeShashank