Enum DcRegion
pub enum DcRegion {
Ap,
Us,
}Expand description
Data center region used for API gateway routing.
Independent of [is_cn]: that picks the *.longbridge.cn vs
*.longbridge.com host (mainland acceleration), while this selects which
data center (us/ap) the gateway sources data from.
Variants§
Implementations§
§impl DcRegion
impl DcRegion
pub fn from_credential(credential: &str) -> DcRegion
pub fn from_credential(credential: &str) -> DcRegion
Derive the region from a single credential’s prefix.
Longbridge credentials — the OAuth access token, and the legacy API-key
app_key / app_secret / access_token — are prefixed with their data
center: us_… for the US data center, ap_… for Asia-Pacific. A us_
prefix maps to DcRegion::Us; everything else — including
ap_-prefixed and unprefixed credentials — maps to
DcRegion::Ap, matching the gateway default. A leading Bearer
is tolerated so an Authorization value can be passed directly.
pub fn from_credentials(credentials: &[&str]) -> DcRegion
pub fn from_credentials(credentials: &[&str]) -> DcRegion
Derive the region from a set of credentials, returning DcRegion::Us
if any of them carries the us_ prefix.
Used for legacy API-key auth, where the app_key, app_secret, and
access_token all carry the region prefix.
pub fn as_str(self) -> &'static str
pub fn as_str(self) -> &'static str
The DC_REGION_HEADER value for this region ("us" or "ap").
pub fn allows(self, required: DcRegion) -> bool
pub fn allows(self, required: DcRegion) -> bool
Whether this session may reach an API limited to required.
true when the session’s region matches the API’s required region;
callers short-circuit with a unified error when it is false.
pub fn strip_region_prefix(credential: &str) -> &str
pub fn strip_region_prefix(credential: &str) -> &str
Strip any leading Bearer from a credential.
Region prefixes (hk_m_, us_m_, ap_m_, …) are routing metadata
consumed by [from_credential] to derive the DC_REGION_HEADER.
The gateway accepts the full prefixed token and routes via the header,
so no region prefix is stripped — only Bearer is removed.
Trait Implementations§
impl Copy for DcRegion
impl Eq for DcRegion
impl StructuralPartialEq for DcRegion
Auto Trait Implementations§
impl Freeze for DcRegion
impl RefUnwindSafe for DcRegion
impl Send for DcRegion
impl Sync for DcRegion
impl Unpin for DcRegion
impl UnsafeUnpin for DcRegion
impl UnwindSafe for DcRegion
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more