id stringlengths 11 116 | type stringclasses 1
value | granularity stringclasses 4
values | content stringlengths 16 477k | metadata dict |
|---|---|---|---|---|
fn_clm_api_models_get_api_event_type_-3929976624230935782 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/events/routing
// Implementation of crate::open_router::UpdateScoreResponse for ApiEventMetric
fn get_api_event_type(&self) -> Option<ApiEventsType> {
Some(ApiEventsType::Routing)
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 26,
"total_crates": null
} |
fn_clm_api_models_get_api_event_type_9156738102114714512 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/events/apple_pay_certificates_migration
// Implementation of ApplePayCertificatesMigrationResponse for ApiEventMetric
fn get_api_event_type(&self) -> Option<common_utils::events::ApiEventsType> {
Some(common_utils::events::ApiEventsType::ApplePayCertificatesMigration)
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 26,
"total_crates": null
} |
fn_clm_api_models_new_7518911253672902741 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/payment_intents
// Inherent implementation for PaymentIntentMetricsBucketIdentifier
pub fn new(
status: Option<IntentStatus>,
currency: Option<Currency>,
profile_id: Option<String>,
connector: Option<String>,
auth_type: Option<AuthenticationType>,
payment_method: Option<String>,
payment_method_type: Option<String>,
card_network: Option<String>,
merchant_id: Option<String>,
card_last_4: Option<String>,
card_issuer: Option<String>,
error_reason: Option<String>,
normalized_time_range: TimeRange,
) -> Self {
Self {
status,
currency,
profile_id,
connector,
auth_type,
payment_method,
payment_method_type,
card_network,
merchant_id,
card_last_4,
card_issuer,
error_reason,
time_bucket: normalized_time_range,
start_time: normalized_time_range.start_time,
}
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14463,
"total_crates": null
} |
fn_clm_api_models_from_7518911253672902741 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/payment_intents
// Implementation of NameDescription for From<PaymentIntentDimensions>
fn from(value: PaymentIntentDimensions) -> Self {
Self {
name: value.to_string(),
desc: String::new(),
}
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2604,
"total_crates": null
} |
fn_clm_api_models_eq_7518911253672902741 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/payment_intents
// Implementation of PaymentIntentMetricsBucketIdentifier for PartialEq
fn eq(&self, other: &Self) -> bool {
let mut left = DefaultHasher::new();
self.hash(&mut left);
let mut right = DefaultHasher::new();
other.hash(&mut right);
left.finish() == right.finish()
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 1670,
"total_crates": null
} |
fn_clm_api_models_hash_7518911253672902741 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/payment_intents
// Implementation of PaymentIntentMetricsBucketIdentifier for Hash
fn hash<H: Hasher>(&self, state: &mut H) {
self.status.map(|i| i.to_string()).hash(state);
self.currency.hash(state);
self.profile_id.hash(state);
self.connector.hash(state);
self.auth_type.map(|i| i.to_string()).hash(state);
self.payment_method.hash(state);
self.payment_method_type.hash(state);
self.card_network.hash(state);
self.merchant_id.hash(state);
self.card_last_4.hash(state);
self.card_issuer.hash(state);
self.error_reason.hash(state);
self.time_bucket.hash(state);
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 375,
"total_crates": null
} |
fn_clm_api_models_is_forex_metric_7518911253672902741 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/payment_intents
// Implementation of PaymentIntentMetrics for ForexMetric
fn is_forex_metric(&self) -> bool {
matches!(
self,
Self::PaymentProcessedAmount
| Self::SmartRetriedAmount
| Self::SessionizedPaymentProcessedAmount
| Self::SessionizedSmartRetriedAmount
)
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 20,
"total_crates": null
} |
fn_clm_api_models_new_-7996058887255924228 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/api_event
// Inherent implementation for ApiEventMetricsBucketIdentifier
pub fn new(normalized_time_range: TimeRange) -> Self {
Self {
time_bucket: normalized_time_range,
start_time: normalized_time_range.start_time,
}
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14463,
"total_crates": null
} |
fn_clm_api_models_from_-7996058887255924228 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/api_event
// Implementation of NameDescription for From<ApiEventMetrics>
fn from(value: ApiEventMetrics) -> Self {
Self {
name: value.to_string(),
desc: String::new(),
}
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2604,
"total_crates": null
} |
fn_clm_api_models_eq_-7996058887255924228 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/api_event
// Implementation of ApiEventMetricsBucketIdentifier for PartialEq
fn eq(&self, other: &Self) -> bool {
let mut left = DefaultHasher::new();
self.hash(&mut left);
let mut right = DefaultHasher::new();
other.hash(&mut right);
left.finish() == right.finish()
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 1670,
"total_crates": null
} |
fn_clm_api_models_hash_-7996058887255924228 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/api_event
// Implementation of ApiEventMetricsBucketIdentifier for Hash
fn hash<H: Hasher>(&self, state: &mut H) {
self.time_bucket.hash(state);
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 343,
"total_crates": null
} |
fn_clm_api_models_new_-4153158224871881047 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/refunds
// Inherent implementation for RefundMetricsBucketIdentifier
pub fn new(
currency: Option<Currency>,
refund_status: Option<String>,
connector: Option<String>,
refund_type: Option<String>,
profile_id: Option<String>,
refund_reason: Option<String>,
refund_error_message: Option<String>,
normalized_time_range: TimeRange,
) -> Self {
Self {
currency,
refund_status,
connector,
refund_type,
profile_id,
refund_reason,
refund_error_message,
time_bucket: normalized_time_range,
start_time: normalized_time_range.start_time,
}
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14463,
"total_crates": null
} |
fn_clm_api_models_from_-4153158224871881047 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/refunds
// Implementation of NameDescription for From<RefundDimensions>
fn from(value: RefundDimensions) -> Self {
Self {
name: value.to_string(),
desc: String::new(),
}
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2604,
"total_crates": null
} |
fn_clm_api_models_eq_-4153158224871881047 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/refunds
// Implementation of RefundMetricsBucketIdentifier for PartialEq
fn eq(&self, other: &Self) -> bool {
let mut left = DefaultHasher::new();
self.hash(&mut left);
let mut right = DefaultHasher::new();
other.hash(&mut right);
left.finish() == right.finish()
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 1670,
"total_crates": null
} |
fn_clm_api_models_hash_-4153158224871881047 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/refunds
// Implementation of RefundMetricsBucketIdentifier for Hash
fn hash<H: Hasher>(&self, state: &mut H) {
self.currency.hash(state);
self.refund_status.hash(state);
self.connector.hash(state);
self.refund_type.hash(state);
self.profile_id.hash(state);
self.refund_reason.hash(state);
self.refund_error_message.hash(state);
self.time_bucket.hash(state);
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 357,
"total_crates": null
} |
fn_clm_api_models_is_forex_metric_-4153158224871881047 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/refunds
// Implementation of RefundMetrics for ForexMetric
fn is_forex_metric(&self) -> bool {
matches!(
self,
Self::RefundProcessedAmount | Self::SessionizedRefundProcessedAmount
)
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 20,
"total_crates": null
} |
fn_clm_api_models_new_-8067927215512100952 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/payments
// Inherent implementation for PaymentMetricsBucketIdentifier
pub fn new(
currency: Option<Currency>,
status: Option<AttemptStatus>,
connector: Option<String>,
auth_type: Option<AuthenticationType>,
payment_method: Option<String>,
payment_method_type: Option<String>,
client_source: Option<String>,
client_version: Option<String>,
profile_id: Option<String>,
card_network: Option<String>,
merchant_id: Option<String>,
card_last_4: Option<String>,
card_issuer: Option<String>,
error_reason: Option<String>,
routing_approach: Option<RoutingApproach>,
signature_network: Option<String>,
is_issuer_regulated: Option<bool>,
is_debit_routed: Option<bool>,
normalized_time_range: TimeRange,
) -> Self {
Self {
currency,
status,
connector,
auth_type,
payment_method,
payment_method_type,
client_source,
client_version,
profile_id,
card_network,
merchant_id,
card_last_4,
card_issuer,
error_reason,
routing_approach,
signature_network,
is_issuer_regulated,
is_debit_routed,
time_bucket: normalized_time_range,
start_time: normalized_time_range.start_time,
}
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14463,
"total_crates": null
} |
fn_clm_api_models_from_-8067927215512100952 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/payments
// Implementation of NameDescription for From<PaymentDimensions>
fn from(value: PaymentDimensions) -> Self {
Self {
name: value.to_string(),
desc: String::new(),
}
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2604,
"total_crates": null
} |
fn_clm_api_models_eq_-8067927215512100952 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/payments
// Implementation of PaymentMetricsBucketIdentifier for PartialEq
fn eq(&self, other: &Self) -> bool {
let mut left = DefaultHasher::new();
self.hash(&mut left);
let mut right = DefaultHasher::new();
other.hash(&mut right);
left.finish() == right.finish()
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 1670,
"total_crates": null
} |
fn_clm_api_models_hash_-8067927215512100952 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/payments
// Implementation of PaymentMetricsBucketIdentifier for Hash
fn hash<H: Hasher>(&self, state: &mut H) {
self.currency.hash(state);
self.status.map(|i| i.to_string()).hash(state);
self.connector.hash(state);
self.auth_type.map(|i| i.to_string()).hash(state);
self.payment_method.hash(state);
self.payment_method_type.hash(state);
self.client_source.hash(state);
self.client_version.hash(state);
self.profile_id.hash(state);
self.card_network.hash(state);
self.merchant_id.hash(state);
self.card_last_4.hash(state);
self.card_issuer.hash(state);
self.error_reason.hash(state);
self.routing_approach
.clone()
.map(|i| i.to_string())
.hash(state);
self.signature_network.hash(state);
self.is_issuer_regulated.hash(state);
self.is_debit_routed.hash(state);
self.time_bucket.hash(state);
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 393,
"total_crates": null
} |
fn_clm_api_models_is_forex_metric_-8067927215512100952 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/payments
// Implementation of PaymentMetrics for ForexMetric
fn is_forex_metric(&self) -> bool {
matches!(
self,
Self::PaymentProcessedAmount
| Self::AvgTicketSize
| Self::DebitRouting
| Self::SessionizedPaymentProcessedAmount
| Self::SessionizedAvgTicketSize
| Self::SessionizedDebitRouting,
)
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 20,
"total_crates": null
} |
fn_clm_api_models_new_6047362071030924709 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/auth_events
// Inherent implementation for AuthEventMetricsBucketIdentifier
pub fn new(
authentication_status: Option<AuthenticationStatus>,
trans_status: Option<TransactionStatus>,
authentication_type: Option<DecoupledAuthenticationType>,
error_message: Option<String>,
authentication_connector: Option<AuthenticationConnectors>,
message_version: Option<String>,
acs_reference_number: Option<String>,
mcc: Option<String>,
currency: Option<Currency>,
merchant_country: Option<String>,
billing_country: Option<String>,
shipping_country: Option<String>,
issuer_country: Option<String>,
earliest_supported_version: Option<String>,
latest_supported_version: Option<String>,
whitelist_decision: Option<bool>,
device_manufacturer: Option<String>,
device_type: Option<String>,
device_brand: Option<String>,
device_os: Option<String>,
device_display: Option<String>,
browser_name: Option<String>,
browser_version: Option<String>,
issuer_id: Option<String>,
scheme_name: Option<String>,
exemption_requested: Option<bool>,
exemption_accepted: Option<bool>,
normalized_time_range: TimeRange,
) -> Self {
Self {
authentication_status,
trans_status,
authentication_type,
error_message,
authentication_connector,
message_version,
acs_reference_number,
mcc,
currency,
merchant_country,
billing_country,
shipping_country,
issuer_country,
earliest_supported_version,
latest_supported_version,
whitelist_decision,
device_manufacturer,
device_type,
device_brand,
device_os,
device_display,
browser_name,
browser_version,
issuer_id,
scheme_name,
exemption_requested,
exemption_accepted,
time_bucket: normalized_time_range,
start_time: normalized_time_range.start_time,
}
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14463,
"total_crates": null
} |
fn_clm_api_models_from_6047362071030924709 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/auth_events
// Implementation of NameDescription for From<AuthEventDimensions>
fn from(value: AuthEventDimensions) -> Self {
Self {
name: value.to_string(),
desc: String::new(),
}
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2604,
"total_crates": null
} |
fn_clm_api_models_eq_6047362071030924709 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/auth_events
// Implementation of AuthEventMetricsBucketIdentifier for PartialEq
fn eq(&self, other: &Self) -> bool {
let mut left = DefaultHasher::new();
self.hash(&mut left);
let mut right = DefaultHasher::new();
other.hash(&mut right);
left.finish() == right.finish()
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 1670,
"total_crates": null
} |
fn_clm_api_models_hash_6047362071030924709 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/auth_events
// Implementation of AuthEventMetricsBucketIdentifier for Hash
fn hash<H: Hasher>(&self, state: &mut H) {
self.authentication_status.hash(state);
self.trans_status.hash(state);
self.authentication_type.hash(state);
self.authentication_connector.hash(state);
self.message_version.hash(state);
self.acs_reference_number.hash(state);
self.error_message.hash(state);
self.mcc.hash(state);
self.currency.hash(state);
self.merchant_country.hash(state);
self.billing_country.hash(state);
self.shipping_country.hash(state);
self.issuer_country.hash(state);
self.earliest_supported_version.hash(state);
self.latest_supported_version.hash(state);
self.whitelist_decision.hash(state);
self.device_manufacturer.hash(state);
self.device_type.hash(state);
self.device_brand.hash(state);
self.device_os.hash(state);
self.device_display.hash(state);
self.browser_name.hash(state);
self.browser_version.hash(state);
self.issuer_id.hash(state);
self.scheme_name.hash(state);
self.exemption_requested.hash(state);
self.exemption_accepted.hash(state);
self.time_bucket.hash(state);
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 397,
"total_crates": null
} |
fn_clm_api_models_new_4724061517253240727 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/disputes
// Inherent implementation for DisputeMetricsBucketIdentifier
pub fn new(
dispute_stage: Option<DisputeStage>,
connector: Option<String>,
currency: Option<Currency>,
normalized_time_range: TimeRange,
) -> Self {
Self {
dispute_stage,
connector,
currency,
time_bucket: normalized_time_range,
start_time: normalized_time_range.start_time,
}
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14463,
"total_crates": null
} |
fn_clm_api_models_from_4724061517253240727 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/disputes
// Implementation of NameDescription for From<DisputeMetrics>
fn from(value: DisputeMetrics) -> Self {
Self {
name: value.to_string(),
desc: String::new(),
}
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2604,
"total_crates": null
} |
fn_clm_api_models_eq_4724061517253240727 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/disputes
// Implementation of DisputeMetricsBucketIdentifier for PartialEq
fn eq(&self, other: &Self) -> bool {
let mut left = DefaultHasher::new();
self.hash(&mut left);
let mut right = DefaultHasher::new();
other.hash(&mut right);
left.finish() == right.finish()
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 1670,
"total_crates": null
} |
fn_clm_api_models_hash_4724061517253240727 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/disputes
// Implementation of DisputeMetricsBucketIdentifier for Hash
fn hash<H: Hasher>(&self, state: &mut H) {
self.dispute_stage.hash(state);
self.connector.hash(state);
self.currency.hash(state);
self.time_bucket.hash(state);
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 349,
"total_crates": null
} |
fn_clm_api_models_is_forex_metric_4724061517253240727 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/disputes
// Implementation of DisputeMetrics for ForexMetric
fn is_forex_metric(&self) -> bool {
matches!(
self,
Self::TotalAmountDisputed | Self::TotalDisputeLostAmount
)
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 20,
"total_crates": null
} |
fn_clm_api_models_new_1010546913635661104 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/frm
// Inherent implementation for FrmMetricsBucketIdentifier
pub fn new(
frm_status: Option<String>,
frm_name: Option<String>,
frm_transaction_type: Option<String>,
normalized_time_range: TimeRange,
) -> Self {
Self {
frm_status,
frm_name,
frm_transaction_type,
time_bucket: normalized_time_range,
start_time: normalized_time_range.start_time,
}
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14463,
"total_crates": null
} |
fn_clm_api_models_from_1010546913635661104 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/frm
// Implementation of NameDescription for From<FrmDimensions>
fn from(value: FrmDimensions) -> Self {
Self {
name: value.to_string(),
desc: String::new(),
}
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2604,
"total_crates": null
} |
fn_clm_api_models_eq_1010546913635661104 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/frm
// Implementation of FrmMetricsBucketIdentifier for PartialEq
fn eq(&self, other: &Self) -> bool {
let mut left = DefaultHasher::new();
self.hash(&mut left);
let mut right = DefaultHasher::new();
other.hash(&mut right);
left.finish() == right.finish()
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 1670,
"total_crates": null
} |
fn_clm_api_models_hash_1010546913635661104 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/frm
// Implementation of FrmMetricsBucketIdentifier for Hash
fn hash<H: Hasher>(&self, state: &mut H) {
self.frm_status.hash(state);
self.frm_name.hash(state);
self.frm_transaction_type.hash(state);
self.time_bucket.hash(state);
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 349,
"total_crates": null
} |
fn_clm_api_models_new_-8166346604476905081 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/active_payments
// Inherent implementation for ActivePaymentsMetricsBucketIdentifier
pub fn new(time_bucket: Option<String>) -> Self {
Self { time_bucket }
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14463,
"total_crates": null
} |
fn_clm_api_models_from_-8166346604476905081 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/active_payments
// Implementation of NameDescription for From<ActivePaymentsMetrics>
fn from(value: ActivePaymentsMetrics) -> Self {
Self {
name: value.to_string(),
desc: String::new(),
}
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2604,
"total_crates": null
} |
fn_clm_api_models_eq_-8166346604476905081 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/active_payments
// Implementation of ActivePaymentsMetricsBucketIdentifier for PartialEq
fn eq(&self, other: &Self) -> bool {
let mut left = DefaultHasher::new();
self.hash(&mut left);
let mut right = DefaultHasher::new();
other.hash(&mut right);
left.finish() == right.finish()
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 1670,
"total_crates": null
} |
fn_clm_api_models_hash_-8166346604476905081 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/active_payments
// Implementation of ActivePaymentsMetricsBucketIdentifier for Hash
fn hash<H: Hasher>(&self, state: &mut H) {
self.time_bucket.hash(state);
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 343,
"total_crates": null
} |
fn_clm_api_models_is_all_none_-4517366609312514188 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/search
// Inherent implementation for SearchFilters
pub fn is_all_none(&self) -> bool {
self.payment_method.is_none()
&& self.currency.is_none()
&& self.status.is_none()
&& self.customer_email.is_none()
&& self.search_tags.is_none()
&& self.connector.is_none()
&& self.payment_method_type.is_none()
&& self.card_network.is_none()
&& self.card_last_4.is_none()
&& self.payment_id.is_none()
&& self.amount.is_none()
&& self.customer_id.is_none()
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 48,
"total_crates": null
} |
fn_clm_api_models_new_2517877275784176932 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/sdk_events
// Inherent implementation for SdkEventMetricsBucketIdentifier
pub fn new(
payment_method: Option<String>,
platform: Option<String>,
browser_name: Option<String>,
source: Option<String>,
component: Option<String>,
payment_experience: Option<String>,
time_bucket: Option<String>,
) -> Self {
Self {
payment_method,
platform,
browser_name,
source,
component,
payment_experience,
time_bucket,
}
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14463,
"total_crates": null
} |
fn_clm_api_models_from_2517877275784176932 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/sdk_events
// Implementation of NameDescription for From<SdkEventDimensions>
fn from(value: SdkEventDimensions) -> Self {
Self {
name: value.to_string(),
desc: String::new(),
}
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2604,
"total_crates": null
} |
fn_clm_api_models_eq_2517877275784176932 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/sdk_events
// Implementation of SdkEventMetricsBucketIdentifier for PartialEq
fn eq(&self, other: &Self) -> bool {
let mut left = DefaultHasher::new();
self.hash(&mut left);
let mut right = DefaultHasher::new();
other.hash(&mut right);
left.finish() == right.finish()
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 1670,
"total_crates": null
} |
fn_clm_api_models_hash_2517877275784176932 | clm | function | // Repository: hyperswitch
// Crate: api_models
// Purpose: External API request/response types (what clients see)
// Module: crates/api_models/src/analytics/sdk_events
// Implementation of SdkEventMetricsBucketIdentifier for Hash
fn hash<H: Hasher>(&self, state: &mut H) {
self.payment_method.hash(state);
self.platform.hash(state);
self.browser_name.hash(state);
self.source.hash(state);
self.component.hash(state);
self.payment_experience.hash(state);
self.time_bucket.hash(state);
}
| {
"crate": "api_models",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 355,
"total_crates": null
} |
fn_clm_router_env_main_2224544886447532853 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/build
fn main() {
vergen::generate_cargo_instructions();
cargo_workspace::verify_cargo_metadata_format();
cargo_workspace::set_cargo_workspace_members_env();
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 6,
"total_crates": null
} |
fn_clm_router_env_logger_-3283779011313747271 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/tests/logger
fn logger() -> error_stack::Result<&'static TelemetryGuard, ConfigError> {
use std::sync::OnceLock;
static INSTANCE: OnceLock<TelemetryGuard> = OnceLock::new();
Ok(INSTANCE.get_or_init(|| {
let config = router_env::Config::new().unwrap();
router_env::setup(&config.log, "router_env_test", []).unwrap()
}))
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 11,
"total_crates": null
} |
fn_clm_router_env_basic_-3283779011313747271 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/tests/logger
async fn basic() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
logger()?;
fn_with_colon(13).await;
Ok(())
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 4,
"total_crates": null
} |
fn_clm_router_env_fn_with_colon_-1559977290335611586 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/tests/test_module
pub async fn fn_with_colon(val: i32) {
let a = 13;
let b = 31;
logger::log!(
logger::Level::WARN,
?a,
?b,
tag = ?logger::Tag::ApiIncomingRequest,
category = ?logger::Category::Api,
flow = "some_flow",
session_id = "some_session",
answer = 13,
message2 = "yyy",
message = "Experiment",
val,
);
fn_without_colon(131).await;
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 15,
"total_crates": null
} |
fn_clm_router_env_fn_without_colon_-1559977290335611586 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/tests/test_module
pub async fn fn_without_colon(val: i32) {
let a = 13;
let b = 31;
// trace_macros!(true);
logger::log!(
logger::Level::INFO,
?a,
?b,
tag = ?logger::Tag::ApiIncomingRequest,
category = ?logger::Category::Api,
flow = "some_flow",
session_id = "some_session",
answer = 13,
message2 = "yyy",
message = "Experiment",
val,
);
// trace_macros!(false);
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 13,
"total_crates": null
} |
fn_clm_router_env_basic_7478459033502217048 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/tests/env
async fn basic() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
println!("CARGO_PKG_VERSION : {:?}", env!("CARGO_PKG_VERSION"));
println!("CARGO_PROFILE : {:?}", env!("CARGO_PROFILE"));
println!(
"GIT_COMMIT_TIMESTAMP : {:?}",
env!("VERGEN_GIT_COMMIT_TIMESTAMP")
);
println!("GIT_SHA : {:?}", env!("VERGEN_GIT_SHA"));
println!("RUSTC_SEMVER : {:?}", env!("VERGEN_RUSTC_SEMVER"));
println!(
"CARGO_TARGET_TRIPLE : {:?}",
env!("VERGEN_CARGO_TARGET_TRIPLE")
);
Ok(())
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 0,
"total_crates": null
} |
fn_clm_router_env_env_macro_7478459033502217048 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/tests/env
async fn env_macro() {
println!("version : {:?}", env::version!());
println!("build : {:?}", env::build!());
println!("commit : {:?}", env::commit!());
// println!("platform : {:?}", env::platform!());
assert!(!env::version!().is_empty());
assert!(!env::build!().is_empty());
assert!(!env::commit!().is_empty());
// assert!(env::platform!().len() > 0);
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 0,
"total_crates": null
} |
fn_clm_router_env_generate_cargo_instructions_6908143402024095378 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/vergen
pub fn generate_cargo_instructions() {}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 19,
"total_crates": null
} |
fn_clm_router_env_which_7693002332316351178 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/env
/// Name of current environment. Either "development", "sandbox" or "production".
pub fn which() -> Env {
#[cfg(debug_assertions)]
let default_env = Env::Development;
#[cfg(not(debug_assertions))]
let default_env = Env::Production;
std::env::var(vars::RUN_ENV).map_or_else(|_| default_env, |v| v.parse().unwrap_or(default_env))
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 57,
"total_crates": null
} |
fn_clm_router_env_workspace_path_7693002332316351178 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/env
/// Path to the root directory of the cargo workspace.
/// It is recommended that this be used by the application as the base path to build other paths
/// such as configuration and logs directories.
pub fn workspace_path() -> PathBuf {
if let Ok(manifest_dir) = std::env::var(vars::CARGO_MANIFEST_DIR) {
let mut path = PathBuf::from(manifest_dir);
path.pop();
path.pop();
path
} else {
PathBuf::from(".")
}
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 35,
"total_crates": null
} |
fn_clm_router_env_prefix_for_env_7693002332316351178 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/env
/// Three letter (lowercase) prefix corresponding to the current environment.
/// Either `dev`, `snd` or `prd`.
pub fn prefix_for_env() -> &'static str {
match which() {
Env::Development => "dev",
Env::Sandbox => "snd",
Env::Production => "prd",
}
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 18,
"total_crates": null
} |
fn_clm_router_env_f64_histogram_buckets_-8429734805293826079 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/metrics
pub fn f64_histogram_buckets() -> Vec<f64> {
let mut init = 0.01;
let mut buckets: [f64; 15] = [0.0; 15];
for bucket in &mut buckets {
init *= 2.0;
*bucket = init;
}
Vec::from(buckets)
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 12,
"total_crates": null
} |
fn_clm_router_env_set_cargo_workspace_members_env_3744130306027947775 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/cargo_workspace
pub fn set_cargo_workspace_members_env() {
use std::io::Write;
let metadata = cargo_metadata::MetadataCommand::new()
.exec()
.expect("Failed to obtain cargo metadata");
let workspace_members = metadata
.workspace_packages()
.iter()
.map(|package| package.name.as_str())
.collect::<Vec<_>>()
.join(",");
writeln!(
&mut std::io::stdout(),
"cargo:rustc-env=CARGO_WORKSPACE_MEMBERS={workspace_members}"
)
.expect("Failed to set `CARGO_WORKSPACE_MEMBERS` environment variable");
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 27,
"total_crates": null
} |
fn_clm_router_env_verify_cargo_metadata_format_3744130306027947775 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/cargo_workspace
/// Verify that the cargo metadata workspace packages format matches that expected by
/// [`set_cargo_workspace_members_env`] to set the `CARGO_WORKSPACE_MEMBERS` environment variable.
///
/// This function should be typically called within build scripts, before the
/// [`set_cargo_workspace_members_env`] function is called.
///
/// # Panics
///
/// Panics if running the `cargo metadata` command fails, or if the workspace member package names
/// cannot be determined.
pub fn verify_cargo_metadata_format() {
#[allow(clippy::expect_used)]
let metadata = cargo_metadata::MetadataCommand::new()
.exec()
.expect("Failed to obtain cargo metadata");
assert!(
metadata
.workspace_packages()
.iter()
.any(|package| package.name == env!("CARGO_PKG_NAME")),
"Unable to determine workspace member package names from `cargo metadata`"
);
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 17,
"total_crates": null
} |
fn_clm_router_env_new_-5812462620863543274 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/logger/config
// Implementation of None for Config
/// Default constructor.
pub fn new() -> Result<Self, config::ConfigError> {
Self::new_with_config_path(None)
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14465,
"total_crates": null
} |
fn_clm_router_env_deserialize_-5812462620863543274 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/logger/config
// Implementation of Level for Deserialize<'de>
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
use std::str::FromStr as _;
let s = String::deserialize(deserializer)?;
tracing::Level::from_str(&s)
.map(Level)
.map_err(serde::de::Error::custom)
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 142,
"total_crates": null
} |
fn_clm_router_env_builder_-5812462620863543274 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/logger/config
// Implementation of None for Config
/// Construct config builder extending it by fall-back defaults and setting config file to load.
pub fn builder(
environment: &str,
) -> Result<config::ConfigBuilder<config::builder::DefaultState>, config::ConfigError> {
config::Config::builder()
// Here, it should be `set_override()` not `set_default()`.
// "env" can't be altered by config field.
// Should be single source of truth.
.set_override("env", environment)
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 103,
"total_crates": null
} |
fn_clm_router_env_new_with_config_path_-5812462620863543274 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/logger/config
// Implementation of None for Config
/// Constructor expecting config path set explicitly.
pub fn new_with_config_path(
explicit_config_path: Option<PathBuf>,
) -> Result<Self, config::ConfigError> {
// Configuration values are picked up in the following priority order (1 being least
// priority):
// 1. Defaults from the implementation of the `Default` trait.
// 2. Values from config file. The config file accessed depends on the environment
// specified by the `RUN_ENV` environment variable. `RUN_ENV` can be one of
// `development`, `sandbox` or `production`. If nothing is specified for `RUN_ENV`,
// `/config/development.toml` file is read.
// 3. Environment variables prefixed with `ROUTER` and each level separated by double
// underscores.
//
// Values in config file override the defaults in `Default` trait, and the values set using
// environment variables override both the defaults and the config file values.
let environment = crate::env::which();
let config_path = Self::config_path(&environment.to_string(), explicit_config_path);
let config = Self::builder(&environment.to_string())?
.add_source(config::File::from(config_path).required(false))
.add_source(config::Environment::with_prefix("ROUTER").separator("__"))
.build()?;
// The logger may not yet be initialized when constructing the application configuration
#[allow(clippy::print_stderr)]
serde_path_to_error::deserialize(config).map_err(|error| {
crate::error!(%error, "Unable to deserialize configuration");
eprintln!("Unable to deserialize application configuration: {error}");
error.into_inner()
})
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 51,
"total_crates": null
} |
fn_clm_router_env_get_config_directory_-5812462620863543274 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/logger/config
// Implementation of None for Config
/// Get the Directory for the config file
/// Read the env variable `CONFIG_DIR` or fallback to `config`
pub fn get_config_directory() -> PathBuf {
let mut config_path = PathBuf::new();
let config_directory =
std::env::var(crate::env::vars::CONFIG_DIR).unwrap_or_else(|_| "config".into());
config_path.push(crate::env::workspace_path());
config_path.push(config_directory);
config_path
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 38,
"total_crates": null
} |
fn_clm_router_env_new_2422682527716497478 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/logger/formatter
// Implementation of None for FormattingLayer<W, F>
/// Constructor of `FormattingLayer`.
///
/// A `name` will be attached to all records during formatting.
/// A `dst_writer` to forward all records.
///
/// ## Example
/// ```rust
/// let formatting_layer = router_env::FormattingLayer::new("my_service", std::io::stdout, serde_json::ser::CompactFormatter);
/// ```
pub fn new(
service: &str,
dst_writer: W,
formatter: F,
) -> error_stack::Result<Self, ConfigError> {
Self::new_with_implicit_entries(service, dst_writer, HashMap::new(), formatter)
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14467,
"total_crates": null
} |
fn_clm_router_env_common_serialize_2422682527716497478 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/logger/formatter
// Implementation of None for FormattingLayer<W, F>
/// Serialize common for both span and event entries.
fn common_serialize<S>(
&self,
map_serializer: &mut impl SerializeMap<Error = serde_json::Error>,
metadata: &Metadata<'_>,
span: Option<&SpanRef<'_, S>>,
storage: &Storage<'_>,
name: &str,
) -> Result<(), std::io::Error>
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
let is_extra = |s: &str| !IMPLICIT_KEYS.contains(s);
let is_extra_implicit = |s: &str| is_extra(s) && EXTRA_IMPLICIT_KEYS.contains(s);
map_serializer.serialize_entry(HOSTNAME, &self.hostname)?;
map_serializer.serialize_entry(PID, &self.pid)?;
map_serializer.serialize_entry(ENV, &self.env)?;
#[cfg(feature = "vergen")]
map_serializer.serialize_entry(VERSION, &self.version)?;
#[cfg(feature = "vergen")]
map_serializer.serialize_entry(BUILD, &self.build)?;
map_serializer.serialize_entry(LEVEL, &format_args!("{}", metadata.level()))?;
map_serializer.serialize_entry(TARGET, metadata.target())?;
map_serializer.serialize_entry(SERVICE, &self.service)?;
map_serializer.serialize_entry(LINE, &metadata.line())?;
map_serializer.serialize_entry(FILE, &metadata.file())?;
map_serializer.serialize_entry(FN, name)?;
map_serializer
.serialize_entry(FULL_NAME, &format_args!("{}::{}", metadata.target(), name))?;
if let Ok(time) = &time::OffsetDateTime::now_utc().format(&Iso8601::DEFAULT) {
map_serializer.serialize_entry(TIME, time)?;
}
// Write down implicit default entries.
for (key, value) in self.default_fields.iter() {
map_serializer.serialize_entry(key, value)?;
}
#[cfg(feature = "log_custom_entries_to_extra")]
let mut extra = serde_json::Map::default();
let mut explicit_entries_set: HashSet<&str> = HashSet::default();
// Write down explicit event's entries.
for (key, value) in storage.values.iter() {
if is_extra_implicit(key) {
#[cfg(feature = "log_extra_implicit_fields")]
map_serializer.serialize_entry(key, value)?;
explicit_entries_set.insert(key);
} else if is_extra(key) {
#[cfg(feature = "log_custom_entries_to_extra")]
extra.insert(key.to_string(), value.clone());
#[cfg(not(feature = "log_custom_entries_to_extra"))]
map_serializer.serialize_entry(key, value)?;
explicit_entries_set.insert(key);
} else {
tracing::warn!(
?key,
?value,
"Attempting to log a reserved entry. It won't be added to the logs"
);
}
}
// Write down entries from the span, if it exists.
if let Some(span) = &span {
let extensions = span.extensions();
if let Some(visitor) = extensions.get::<Storage<'_>>() {
for (key, value) in &visitor.values {
if is_extra_implicit(key) && !explicit_entries_set.contains(key) {
#[cfg(feature = "log_extra_implicit_fields")]
map_serializer.serialize_entry(key, value)?;
} else if is_extra(key) && !explicit_entries_set.contains(key) {
#[cfg(feature = "log_custom_entries_to_extra")]
extra.insert(key.to_string(), value.clone());
#[cfg(not(feature = "log_custom_entries_to_extra"))]
map_serializer.serialize_entry(key, value)?;
} else {
tracing::warn!(
?key,
?value,
"Attempting to log a reserved entry. It won't be added to the logs"
);
}
}
}
}
#[cfg(feature = "log_custom_entries_to_extra")]
map_serializer.serialize_entry("extra", &extra)?;
Ok(())
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 104,
"total_crates": null
} |
fn_clm_router_env_new_with_implicit_entries_2422682527716497478 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/logger/formatter
// Implementation of None for FormattingLayer<W, F>
/// Construct of `FormattingLayer with implicit default entries.
pub fn new_with_implicit_entries(
service: &str,
dst_writer: W,
default_fields: HashMap<String, Value>,
formatter: F,
) -> error_stack::Result<Self, ConfigError> {
let pid = std::process::id();
let hostname = gethostname::gethostname().to_string_lossy().into_owned();
let service = service.to_string();
#[cfg(feature = "vergen")]
let version = crate::version!().to_string();
#[cfg(feature = "vergen")]
let build = crate::build!().to_string();
let env = crate::env::which().to_string();
for key in default_fields.keys() {
if IMPLICIT_KEYS.contains(key.as_str()) {
return Err(ConfigError::Message(format!(
"A reserved key `{key}` was included in `default_fields` in the log formatting layer"
))
.into());
}
}
Ok(Self {
dst_writer,
pid,
hostname,
env,
service,
#[cfg(feature = "vergen")]
version,
#[cfg(feature = "vergen")]
build,
default_fields,
formatter,
})
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 49,
"total_crates": null
} |
fn_clm_router_env_event_serialize_2422682527716497478 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/logger/formatter
// Implementation of None for FormattingLayer<W, F>
/// Serialize event into a buffer of bytes using parent span.
pub fn event_serialize<S>(
&self,
span: Option<&SpanRef<'_, S>>,
event: &Event<'_>,
) -> std::io::Result<Vec<u8>>
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
let mut buffer = Vec::new();
let mut serializer =
serde_json::Serializer::with_formatter(&mut buffer, self.formatter.clone());
let mut map_serializer = serializer.serialize_map(None)?;
let mut storage = Storage::default();
event.record(&mut storage);
let name = span.map_or("?", SpanRef::name);
Self::event_message(span, event, &mut storage);
self.common_serialize(&mut map_serializer, event.metadata(), span, &storage, name)?;
map_serializer.end()?;
Ok(buffer)
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 43,
"total_crates": null
} |
fn_clm_router_env_fmt_2422682527716497478 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/logger/formatter
// Implementation of RecordType for fmt::Display
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let repr = match self {
Self::EnterSpan => "START",
Self::ExitSpan => "END",
Self::Event => "EVENT",
};
write!(f, "{repr}")
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 38,
"total_crates": null
} |
fn_clm_router_env_new_467850286845899013 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/logger/storage
// Inherent implementation for Storage<'a>
/// Default constructor.
pub fn new() -> Self {
Self::default()
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14465,
"total_crates": null
} |
fn_clm_router_env_default_467850286845899013 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/logger/storage
// Implementation of Storage<'_> for Default
fn default() -> Self {
Self {
values: HashMap::new(),
}
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 7705,
"total_crates": null
} |
fn_clm_router_env_record_value_467850286845899013 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/logger/storage
// Inherent implementation for Storage<'a>
pub fn record_value(&mut self, key: &'a str, value: serde_json::Value) {
if super::formatter::IMPLICIT_KEYS.contains(key) {
tracing::warn!(value =? value, "{} is a reserved entry. Skipping it.", key);
} else {
self.values.insert(key, value);
}
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 52,
"total_crates": null
} |
fn_clm_router_env_on_close_467850286845899013 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/logger/storage
// Implementation of StorageSubscription for Layer<S>
/// On close create an entry about how long did it take.
fn on_close(&self, span: Id, ctx: Context<'_, S>) {
#[allow(clippy::expect_used)]
let span = ctx.span(&span).expect("No span");
let elapsed_milliseconds = {
let extensions = span.extensions();
extensions
.get::<Instant>()
.map(|i| i.elapsed().as_millis())
.unwrap_or(0)
};
if let Some(s) = span.extensions().get::<Storage<'_>>() {
s.values.iter().for_each(|(k, v)| {
if PERSISTENT_KEYS.contains(k) {
span.parent().and_then(|p| {
p.extensions_mut()
.get_mut::<Storage<'_>>()
.map(|s| s.record_value(k, v.to_owned()))
});
}
})
};
let mut extensions_mut = span.extensions_mut();
#[allow(clippy::expect_used)]
let visitor = extensions_mut
.get_mut::<Storage<'_>>()
.expect("No visitor in extensions");
if let Ok(elapsed) = serde_json::to_value(elapsed_milliseconds) {
visitor.record_value("elapsed_milliseconds", elapsed);
}
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 46,
"total_crates": null
} |
fn_clm_router_env_on_new_span_467850286845899013 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/logger/storage
// Implementation of StorageSubscription for Layer<S>
/// On new span.
fn on_new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>) {
#[allow(clippy::expect_used)]
let span = ctx.span(id).expect("No span");
let mut extensions = span.extensions_mut();
let mut visitor = if let Some(parent_span) = span.parent() {
let mut extensions = parent_span.extensions_mut();
extensions
.get_mut::<Storage<'_>>()
.map(|v| v.to_owned())
.unwrap_or_default()
} else {
Storage::default()
};
attrs.record(&mut visitor);
extensions.insert(visitor);
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 28,
"total_crates": null
} |
fn_clm_router_env_default_-5379520896373146918 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/logger/defaults
// Implementation of super::config::LogConsole for Default
fn default() -> Self {
Self {
enabled: false,
level: super::config::Level(tracing::Level::INFO),
log_format: super::config::LogFormat::Json,
filtering_directive: None,
}
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 7705,
"total_crates": null
} |
fn_clm_router_env_from_690358128547111026 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/logger/setup
// Implementation of TraceUrlAssert for From<String>
fn from(value: String) -> Self {
match value {
url if url.starts_with('*') => Self::EndsWith(url.trim_start_matches('*').to_string()),
url => Self::Match(url),
}
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2610,
"total_crates": null
} |
fn_clm_router_env_setup_690358128547111026 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/logger/setup
pub fn setup(
config: &config::Log,
service_name: &str,
crates_to_filter: impl AsRef<[&'static str]>,
) -> error_stack::Result<TelemetryGuard, ConfigError> {
let mut guards = Vec::new();
// Setup OpenTelemetry traces and metrics
let traces_layer = if config.telemetry.traces_enabled {
setup_tracing_pipeline(&config.telemetry, service_name)
} else {
None
};
if config.telemetry.metrics_enabled {
setup_metrics_pipeline(&config.telemetry)
};
// Setup file logging
let file_writer = if config.file.enabled {
let mut path = crate::env::workspace_path();
// Using an absolute path for file log path would replace workspace path with absolute path,
// which is the intended behavior for us.
path.push(&config.file.path);
let file_appender = tracing_appender::rolling::hourly(&path, &config.file.file_name);
let (file_writer, guard) = tracing_appender::non_blocking(file_appender);
guards.push(guard);
let file_filter = get_envfilter(
config.file.filtering_directive.as_ref(),
config::Level(tracing::Level::WARN),
config.file.level,
&crates_to_filter,
);
println!("Using file logging filter: {file_filter}");
let layer = FormattingLayer::new(service_name, file_writer, CompactFormatter)?
.with_filter(file_filter);
Some(layer)
} else {
None
};
let subscriber = tracing_subscriber::registry()
.with(traces_layer)
.with(StorageSubscription)
.with(file_writer);
// Setup console logging
if config.console.enabled {
let (console_writer, guard) = tracing_appender::non_blocking(std::io::stdout());
guards.push(guard);
let console_filter = get_envfilter(
config.console.filtering_directive.as_ref(),
config::Level(tracing::Level::WARN),
config.console.level,
&crates_to_filter,
);
println!("Using console logging filter: {console_filter}");
match config.console.log_format {
config::LogFormat::Default => {
let logging_layer = fmt::layer()
.with_timer(fmt::time::time())
.pretty()
.with_writer(console_writer)
.with_filter(console_filter);
subscriber.with(logging_layer).init();
}
config::LogFormat::Json => {
error_stack::Report::set_color_mode(error_stack::fmt::ColorMode::None);
subscriber
.with(
FormattingLayer::new(service_name, console_writer, CompactFormatter)?
.with_filter(console_filter),
)
.init();
}
config::LogFormat::PrettyJson => {
error_stack::Report::set_color_mode(error_stack::fmt::ColorMode::None);
subscriber
.with(
FormattingLayer::new(service_name, console_writer, PrettyFormatter::new())?
.with_filter(console_filter),
)
.init();
}
}
} else {
subscriber.init();
};
// Returning the TelemetryGuard for logs to be printed and metrics to be collected until it is
// dropped
Ok(TelemetryGuard {
_log_guards: guards,
})
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 144,
"total_crates": null
} |
fn_clm_router_env_setup_tracing_pipeline_690358128547111026 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/logger/setup
fn setup_tracing_pipeline(
config: &config::LogTelemetry,
service_name: &str,
) -> Option<
tracing_opentelemetry::OpenTelemetryLayer<
tracing_subscriber::Registry,
opentelemetry_sdk::trace::Tracer,
>,
> {
use opentelemetry::trace::TracerProvider;
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_sdk::trace;
opentelemetry::global::set_text_map_propagator(
opentelemetry_sdk::propagation::TraceContextPropagator::new(),
);
// Set the export interval to 1 second
let batch_config = trace::BatchConfigBuilder::default()
.with_scheduled_delay(Duration::from_millis(1000))
.build();
let exporter_result = opentelemetry_otlp::SpanExporter::builder()
.with_tonic()
.with_export_config(get_opentelemetry_exporter_config(config))
.build();
let exporter = if config.ignore_errors {
#[allow(clippy::print_stderr)] // The logger hasn't been initialized yet
exporter_result
.inspect_err(|error| eprintln!("Failed to build traces exporter: {error:?}"))
.ok()?
} else {
// Safety: This is conditional, there is an option to avoid this behavior at runtime.
#[allow(clippy::expect_used)]
exporter_result.expect("Failed to build traces exporter")
};
let mut provider_builder = trace::TracerProvider::builder()
.with_span_processor(
trace::BatchSpanProcessor::builder(
exporter,
// The runtime would have to be updated if a different web framework is used
opentelemetry_sdk::runtime::TokioCurrentThread,
)
.with_batch_config(batch_config)
.build(),
)
.with_sampler(trace::Sampler::ParentBased(Box::new(ConditionalSampler(
TraceAssertion {
clauses: config
.route_to_trace
.clone()
.map(|inner| inner.into_iter().map(TraceUrlAssert::from).collect()),
default: false,
},
trace::Sampler::TraceIdRatioBased(config.sampling_rate.unwrap_or(1.0)),
))))
.with_resource(opentelemetry_sdk::Resource::new(vec![
opentelemetry::KeyValue::new("service.name", service_name.to_owned()),
]));
if config.use_xray_generator {
provider_builder = provider_builder
.with_id_generator(opentelemetry_aws::trace::XrayIdGenerator::default());
}
Some(
tracing_opentelemetry::layer()
.with_tracer(provider_builder.build().tracer(service_name.to_owned())),
)
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 79,
"total_crates": null
} |
fn_clm_router_env_setup_metrics_pipeline_690358128547111026 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/logger/setup
fn setup_metrics_pipeline(config: &config::LogTelemetry) {
use opentelemetry_otlp::WithExportConfig;
let exporter_result = opentelemetry_otlp::MetricExporter::builder()
.with_tonic()
.with_temporality(opentelemetry_sdk::metrics::Temporality::Cumulative)
.with_export_config(get_opentelemetry_exporter_config(config))
.build();
let exporter = if config.ignore_errors {
#[allow(clippy::print_stderr)] // The logger hasn't been initialized yet
exporter_result
.inspect_err(|error| eprintln!("Failed to build metrics exporter: {error:?}"))
.ok();
return;
} else {
// Safety: This is conditional, there is an option to avoid this behavior at runtime.
#[allow(clippy::expect_used)]
exporter_result.expect("Failed to build metrics exporter")
};
let reader = opentelemetry_sdk::metrics::PeriodicReader::builder(
exporter,
// The runtime would have to be updated if a different web framework is used
opentelemetry_sdk::runtime::TokioCurrentThread,
)
.with_interval(Duration::from_secs(3))
.with_timeout(Duration::from_secs(10))
.build();
let provider = opentelemetry_sdk::metrics::SdkMeterProvider::builder()
.with_reader(reader)
.with_resource(opentelemetry_sdk::Resource::new([
opentelemetry::KeyValue::new(
"pod",
std::env::var("POD_NAME").unwrap_or(String::from("hyperswitch-server-default")),
),
]))
.build();
opentelemetry::global::set_meter_provider(provider);
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 51,
"total_crates": null
} |
fn_clm_router_env_get_envfilter_690358128547111026 | clm | function | // Repository: hyperswitch
// Crate: router_env
// Module: crates/router_env/src/logger/setup
fn get_envfilter(
filtering_directive: Option<&String>,
default_log_level: config::Level,
filter_log_level: config::Level,
crates_to_filter: impl AsRef<[&'static str]>,
) -> EnvFilter {
filtering_directive
.map(|filter| {
// Try to create target filter from specified filtering directive, if set
// Safety: If user is overriding the default filtering directive, then we need to panic
// for invalid directives.
#[allow(clippy::expect_used)]
EnvFilter::builder()
.with_default_directive(default_log_level.into_level().into())
.parse(filter)
.expect("Invalid EnvFilter filtering directive")
})
.unwrap_or_else(|| {
// Construct a default target filter otherwise
let mut workspace_members = crate::cargo_workspace_members!();
workspace_members.extend(crates_to_filter.as_ref());
workspace_members
.drain()
.zip(std::iter::repeat(filter_log_level.into_level()))
.fold(
EnvFilter::default().add_directive(default_log_level.into_level().into()),
|env_filter, (target, level)| {
// Safety: This is a hardcoded basic filtering directive. If even the basic
// filter is wrong, it's better to panic.
#[allow(clippy::expect_used)]
env_filter.add_directive(
format!("{target}={level}")
.parse()
.expect("Invalid EnvFilter directive format"),
)
},
)
})
}
| {
"crate": "router_env",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 46,
"total_crates": null
} |
fn_clm_redis_interface_new_-4012931440397967071 | clm | function | // Repository: hyperswitch
// Crate: redis_interface
// Purpose: User-friendly Redis interface
// Module: crates/redis_interface/src/types
// Inherent implementation for RedisValue
pub fn new(value: FredRedisValue) -> Self {
Self { inner: value }
}
| {
"crate": "redis_interface",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14463,
"total_crates": null
} |
fn_clm_redis_interface_default_-4012931440397967071 | clm | function | // Repository: hyperswitch
// Crate: redis_interface
// Purpose: User-friendly Redis interface
// Module: crates/redis_interface/src/types
// Implementation of RedisSettings for Default
fn default() -> Self {
Self {
host: "127.0.0.1".to_string(),
port: 6379,
cluster_enabled: false,
cluster_urls: vec![],
use_legacy_version: false,
pool_size: 5,
reconnect_max_attempts: 5,
reconnect_delay: 5,
default_ttl: 300,
stream_read_count: 1,
default_hash_ttl: 900,
auto_pipeline: true,
disable_auto_backpressure: false,
max_in_flight_commands: 5000,
default_command_timeout: 30,
max_feed_count: 200,
unresponsive_timeout: 10,
}
}
| {
"crate": "redis_interface",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 7705,
"total_crates": null
} |
fn_clm_redis_interface_from_-4012931440397967071 | clm | function | // Repository: hyperswitch
// Crate: redis_interface
// Purpose: User-friendly Redis interface
// Module: crates/redis_interface/src/types
// Implementation of RedisKey for From<T>
fn from(value: T) -> Self {
let value = value.as_ref();
Self(value.to_string())
}
| {
"crate": "redis_interface",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2606,
"total_crates": null
} |
fn_clm_redis_interface_into_inner_-4012931440397967071 | clm | function | // Repository: hyperswitch
// Crate: redis_interface
// Purpose: User-friendly Redis interface
// Module: crates/redis_interface/src/types
// Inherent implementation for RedisValue
pub fn into_inner(self) -> FredRedisValue {
self.inner
}
| {
"crate": "redis_interface",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2061,
"total_crates": null
} |
fn_clm_redis_interface_validate_-4012931440397967071 | clm | function | // Repository: hyperswitch
// Crate: redis_interface
// Purpose: User-friendly Redis interface
// Module: crates/redis_interface/src/types
// Inherent implementation for RedisSettings
/// Validates the Redis configuration provided.
pub fn validate(&self) -> CustomResult<(), errors::RedisError> {
use common_utils::{ext_traits::ConfigExt, fp_utils::when};
when(self.host.is_default_or_empty(), || {
Err(errors::RedisError::InvalidConfiguration(
"Redis `host` must be specified".into(),
))
})?;
when(self.cluster_enabled && self.cluster_urls.is_empty(), || {
Err(errors::RedisError::InvalidConfiguration(
"Redis `cluster_urls` must be specified if `cluster_enabled` is `true`".into(),
))
})?;
when(
self.default_command_timeout < self.unresponsive_timeout,
|| {
Err(errors::RedisError::InvalidConfiguration(
"Unresponsive timeout cannot be greater than the command timeout".into(),
)
.into())
},
)
}
| {
"crate": "redis_interface",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 243,
"total_crates": null
} |
fn_clm_redis_interface_clone_-3423949352232504364 | clm | function | // Repository: hyperswitch
// Crate: redis_interface
// Purpose: User-friendly Redis interface
// Module: crates/redis_interface/src/lib
// Implementation of None for RedisConnectionPool
pub fn clone(&self, key_prefix: &str) -> Self {
Self {
pool: Arc::clone(&self.pool),
key_prefix: key_prefix.to_string(),
config: Arc::clone(&self.config),
subscriber: Arc::clone(&self.subscriber),
publisher: Arc::clone(&self.publisher),
is_redis_available: Arc::clone(&self.is_redis_available),
}
}
| {
"crate": "redis_interface",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 27345,
"total_crates": null
} |
fn_clm_redis_interface_new_-3423949352232504364 | clm | function | // Repository: hyperswitch
// Crate: redis_interface
// Purpose: User-friendly Redis interface
// Module: crates/redis_interface/src/lib
// Implementation of None for RedisConnectionPool
/// Create a new Redis connection
pub async fn new(conf: &RedisSettings) -> CustomResult<Self, errors::RedisError> {
let redis_connection_url = match conf.cluster_enabled {
// Fred relies on this format for specifying cluster where the host port is ignored & only query parameters are used for node addresses
// redis-cluster://username:password@host:port?node=bar.com:30002&node=baz.com:30003
true => format!(
"redis-cluster://{}:{}?{}",
conf.host,
conf.port,
conf.cluster_urls
.iter()
.flat_map(|url| vec!["&", url])
.skip(1)
.collect::<String>()
),
false => format!(
"redis://{}:{}", //URI Schema
conf.host, conf.port,
),
};
let mut config = fred::types::RedisConfig::from_url(&redis_connection_url)
.change_context(errors::RedisError::RedisConnectionError)?;
let perf = fred::types::PerformanceConfig {
auto_pipeline: conf.auto_pipeline,
default_command_timeout: std::time::Duration::from_secs(conf.default_command_timeout),
max_feed_count: conf.max_feed_count,
backpressure: fred::types::BackpressureConfig {
disable_auto_backpressure: conf.disable_auto_backpressure,
max_in_flight_commands: conf.max_in_flight_commands,
policy: fred::types::BackpressurePolicy::Drain,
},
};
let connection_config = fred::types::ConnectionConfig {
unresponsive_timeout: std::time::Duration::from_secs(conf.unresponsive_timeout),
..fred::types::ConnectionConfig::default()
};
if !conf.use_legacy_version {
config.version = fred::types::RespVersion::RESP3;
}
config.tracing = fred::types::TracingConfig::new(true);
config.blocking = fred::types::Blocking::Error;
let reconnect_policy = fred::types::ReconnectPolicy::new_constant(
conf.reconnect_max_attempts,
conf.reconnect_delay,
);
let subscriber =
SubscriberClient::new(config.clone(), reconnect_policy.clone(), perf.clone()).await?;
let publisher =
RedisClient::new(config.clone(), reconnect_policy.clone(), perf.clone()).await?;
let pool = fred::prelude::RedisPool::new(
config,
Some(perf),
Some(connection_config),
Some(reconnect_policy),
conf.pool_size,
)
.change_context(errors::RedisError::RedisConnectionError)?;
pool.connect();
pool.wait_for_connect()
.await
.change_context(errors::RedisError::RedisConnectionError)?;
let config = RedisConfig::from(conf);
Ok(Self {
pool: Arc::new(pool),
config: Arc::new(config),
is_redis_available: Arc::new(atomic::AtomicBool::new(true)),
subscriber: Arc::new(subscriber),
publisher: Arc::new(publisher),
key_prefix: String::default(),
})
}
| {
"crate": "redis_interface",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14519,
"total_crates": null
} |
fn_clm_redis_interface_from_-3423949352232504364 | clm | function | // Repository: hyperswitch
// Crate: redis_interface
// Purpose: User-friendly Redis interface
// Module: crates/redis_interface/src/lib
// Implementation of RedisConfig for From<&RedisSettings>
fn from(config: &RedisSettings) -> Self {
Self {
default_ttl: config.default_ttl,
default_stream_read_count: config.stream_read_count,
default_hash_ttl: config.default_hash_ttl,
cluster_enabled: config.cluster_enabled,
}
}
| {
"crate": "redis_interface",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2600,
"total_crates": null
} |
fn_clm_redis_interface_on_error_-3423949352232504364 | clm | function | // Repository: hyperswitch
// Crate: redis_interface
// Purpose: User-friendly Redis interface
// Module: crates/redis_interface/src/lib
// Implementation of None for RedisConnectionPool
pub async fn on_error(&self, tx: tokio::sync::oneshot::Sender<()>) {
use futures::StreamExt;
use tokio_stream::wrappers::BroadcastStream;
let error_rxs: Vec<BroadcastStream<fred::error::RedisError>> = self
.pool
.clients()
.iter()
.map(|client| BroadcastStream::new(client.error_rx()))
.collect();
let mut error_rx = futures::stream::select_all(error_rxs);
loop {
if let Some(Ok(error)) = error_rx.next().await {
tracing::error!(?error, "Redis protocol or connection error");
if self.pool.state() == fred::types::ClientState::Disconnected {
if tx.send(()).is_err() {
tracing::error!("The redis shutdown signal sender failed to signal");
}
self.is_redis_available
.store(false, atomic::Ordering::SeqCst);
break;
}
}
}
}
| {
"crate": "redis_interface",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 48,
"total_crates": null
} |
fn_clm_redis_interface_deref_-3423949352232504364 | clm | function | // Repository: hyperswitch
// Crate: redis_interface
// Purpose: User-friendly Redis interface
// Module: crates/redis_interface/src/lib
// Implementation of SubscriberClient for std::ops::Deref
fn deref(&self) -> &Self::Target {
&self.inner
}
| {
"crate": "redis_interface",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 41,
"total_crates": null
} |
fn_clm_redis_interface_get_key_-1211265313444161731 | clm | function | // Repository: hyperswitch
// Crate: redis_interface
// Purpose: User-friendly Redis interface
// Module: crates/redis_interface/src/commands
// Implementation of None for super::RedisConnectionPool
pub async fn get_key<V>(&self, key: &RedisKey) -> CustomResult<V, errors::RedisError>
where
V: FromRedis + Unpin + Send + 'static,
{
match self
.pool
.get(key.tenant_aware_key(self))
.await
.change_context(errors::RedisError::GetFailed)
{
Ok(v) => Ok(v),
Err(_err) => {
#[cfg(not(feature = "multitenancy_fallback"))]
{
Err(_err)
}
#[cfg(feature = "multitenancy_fallback")]
{
self.pool
.get(key.tenant_unaware_key(self))
.await
.change_context(errors::RedisError::GetFailed)
}
}
}
}
| {
"crate": "redis_interface",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 102,
"total_crates": null
} |
fn_clm_redis_interface_delete_key_-1211265313444161731 | clm | function | // Repository: hyperswitch
// Crate: redis_interface
// Purpose: User-friendly Redis interface
// Module: crates/redis_interface/src/commands
// Implementation of None for super::RedisConnectionPool
pub async fn delete_key(&self, key: &RedisKey) -> CustomResult<DelReply, errors::RedisError> {
match self
.pool
.del(key.tenant_aware_key(self))
.await
.change_context(errors::RedisError::DeleteFailed)
{
Ok(v) => Ok(v),
Err(_err) => {
#[cfg(not(feature = "multitenancy_fallback"))]
{
Err(_err)
}
#[cfg(feature = "multitenancy_fallback")]
{
self.pool
.del(key.tenant_unaware_key(self))
.await
.change_context(errors::RedisError::DeleteFailed)
}
}
}
}
| {
"crate": "redis_interface",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 93,
"total_crates": null
} |
fn_clm_redis_interface_set_key_if_not_exists_and_get_value_-1211265313444161731 | clm | function | // Repository: hyperswitch
// Crate: redis_interface
// Purpose: User-friendly Redis interface
// Module: crates/redis_interface/src/commands
// Implementation of None for super::RedisConnectionPool
pub async fn set_key_if_not_exists_and_get_value<V>(
&self,
key: &RedisKey,
value: V,
ttl: Option<i64>,
) -> CustomResult<SetGetReply<V>, errors::RedisError>
where
V: TryInto<RedisValue> + Debug + FromRedis + Send + Sync + serde::de::DeserializeOwned,
V::Error: Into<fred::error::RedisError> + Send + Sync,
{
let redis_key = key.tenant_aware_key(self);
let ttl_seconds = ttl.unwrap_or(self.config.default_ttl.into());
// Get a client from the pool and start transaction
let trx = self.get_transaction();
// Try to set if not exists with expiry - queue the command
trx.set::<(), _, _>(
&redis_key,
value,
Some(Expiration::EX(ttl_seconds)),
Some(SetOptions::NX),
false,
)
.await
.change_context(errors::RedisError::SetFailed)
.attach_printable("Failed to queue set command")?;
// Always get the value after the SET attempt - queue the command
trx.get::<V, _>(&redis_key)
.await
.change_context(errors::RedisError::GetFailed)
.attach_printable("Failed to queue get command")?;
// Execute transaction
let mut results: Vec<RedisValue> = trx
.exec(true)
.await
.change_context(errors::RedisError::SetFailed)
.attach_printable("Failed to execute the redis transaction")?;
let msg = "Got unexpected number of results from transaction";
let get_result = results
.pop()
.ok_or(errors::RedisError::SetFailed)
.attach_printable(msg)?;
let set_result = results
.pop()
.ok_or(errors::RedisError::SetFailed)
.attach_printable(msg)?;
// Parse the GET result to get the actual value
let actual_value: V = FromRedis::from_value(get_result)
.change_context(errors::RedisError::SetFailed)
.attach_printable("Failed to convert from redis value")?;
// Check if SET NX succeeded or failed
match set_result {
// SET NX returns "OK" if key was set
RedisValue::String(_) => Ok(SetGetReply::ValueSet(actual_value)),
// SET NX returns null if key already exists
RedisValue::Null => Ok(SetGetReply::ValueExists(actual_value)),
_ => Err(report!(errors::RedisError::SetFailed))
.attach_printable("Unexpected result from SET NX operation"),
}
}
| {
"crate": "redis_interface",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 78,
"total_crates": null
} |
fn_clm_redis_interface_set_key_with_expiry_-1211265313444161731 | clm | function | // Repository: hyperswitch
// Crate: redis_interface
// Purpose: User-friendly Redis interface
// Module: crates/redis_interface/src/commands
// Implementation of None for super::RedisConnectionPool
pub async fn set_key_with_expiry<V>(
&self,
key: &RedisKey,
value: V,
seconds: i64,
) -> CustomResult<(), errors::RedisError>
where
V: TryInto<RedisValue> + Debug + Send + Sync,
V::Error: Into<fred::error::RedisError> + Send + Sync,
{
self.pool
.set(
key.tenant_aware_key(self),
value,
Some(Expiration::EX(seconds)),
None,
false,
)
.await
.change_context(errors::RedisError::SetExFailed)
}
| {
"crate": "redis_interface",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 74,
"total_crates": null
} |
fn_clm_redis_interface_serialize_and_set_key_with_expiry_-1211265313444161731 | clm | function | // Repository: hyperswitch
// Crate: redis_interface
// Purpose: User-friendly Redis interface
// Module: crates/redis_interface/src/commands
// Implementation of None for super::RedisConnectionPool
pub async fn serialize_and_set_key_with_expiry<V>(
&self,
key: &RedisKey,
value: V,
seconds: i64,
) -> CustomResult<(), errors::RedisError>
where
V: serde::Serialize + Debug,
{
let serialized = value
.encode_to_vec()
.change_context(errors::RedisError::JsonSerializationFailed)?;
self.pool
.set(
key.tenant_aware_key(self),
serialized.as_slice(),
Some(Expiration::EX(seconds)),
None,
false,
)
.await
.change_context(errors::RedisError::SetExFailed)
}
| {
"crate": "redis_interface",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 59,
"total_crates": null
} |
fn_clm_events_new_-8069846008937882624 | clm | function | // Repository: hyperswitch
// Crate: events
// Module: crates/events/src/lib
// Inherent implementation for EventContext<T, A>
/// Create a new event context.
pub fn new(message_sink: A) -> Self {
Self {
message_sink: Arc::new(message_sink),
metadata: HashMap::new(),
}
}
| {
"crate": "events",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14467,
"total_crates": null
} |
fn_clm_events_serialize_-8069846008937882624 | clm | function | // Repository: hyperswitch
// Crate: events
// Module: crates/events/src/lib
// Implementation of FlatMapEvent<T, A> for Serialize
fn serialize<S>(&self, serializer: S) -> core::result::Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut serialize_map: HashMap<_, _> = self
.0
.iter()
.filter_map(|(k, v)| Some((k.clone(), v.masked_serialize().ok()?)))
.collect();
match self.1.data().map(|i| i.masked_serialize()) {
Ok(Ok(Value::Object(map))) => {
for (k, v) in map.into_iter() {
serialize_map.insert(k, v);
}
}
Ok(Ok(i)) => {
serialize_map.insert(self.1.key(), i);
}
i => {
logger::error!("Error serializing event: {:?}", i);
}
};
serialize_map.serialize(serializer)
}
| {
"crate": "events",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 111,
"total_crates": null
} |
fn_clm_events_with_-8069846008937882624 | clm | function | // Repository: hyperswitch
// Crate: events
// Module: crates/events/src/lib
// Inherent implementation for EventBuilder<T, A, E, D>
/// Add metadata to the event.
pub fn with<F: ErasedMaskSerialize, G: EventInfo<Data = F> + 'static>(
mut self,
info: G,
) -> Self {
info.data()
.and_then(|i| {
i.masked_serialize()
.change_context(EventsError::SerializationError)
})
.map_err(|e| {
logger::error!("Error adding event info: {:?}", e);
})
.ok()
.and_then(|data| self.metadata.insert(info.key(), data));
self
}
| {
"crate": "events",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 84,
"total_crates": null
} |
fn_clm_events_emit_-8069846008937882624 | clm | function | // Repository: hyperswitch
// Crate: events
// Module: crates/events/src/lib
// Inherent implementation for EventContext<T, A>
/// Emit an event.
pub fn emit<D, E: Event<EventType = T, Data = D>>(&self, event: E) {
EventBuilder {
message_sink: self.message_sink.clone(),
metadata: self.metadata.clone(),
event,
}
.emit()
}
| {
"crate": "events",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 54,
"total_crates": null
} |
fn_clm_events_event_-8069846008937882624 | clm | function | // Repository: hyperswitch
// Crate: events
// Module: crates/events/src/lib
// Inherent implementation for EventContext<T, A>
/// Create an event builder.
pub fn event<D, E: Event<EventType = T, Data = D>>(
&self,
event: E,
) -> EventBuilder<T, A, E, D> {
EventBuilder {
message_sink: self.message_sink.clone(),
metadata: self.metadata.clone(),
event,
}
}
| {
"crate": "events",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 49,
"total_crates": null
} |
fn_clm_events_key_4298455189869000193 | clm | function | // Repository: hyperswitch
// Crate: events
// Module: crates/events/src/actix
// Implementation of RequestId for EventInfo
fn key(&self) -> String {
"request_id".to_string()
}
| {
"crate": "events",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 31,
"total_crates": null
} |
fn_clm_events_data_4298455189869000193 | clm | function | // Repository: hyperswitch
// Crate: events
// Module: crates/events/src/actix
// Implementation of RequestId for EventInfo
fn data(&self) -> error_stack::Result<String, crate::EventsError> {
Ok(self.as_hyphenated().to_string())
}
| {
"crate": "events",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 27,
"total_crates": null
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.