pub struct ExternallyManaged { /* private fields */ }Expand description
A struct that manages access tokens by utilizing a user-provided refresh function.
The ExternallyManaged struct allows users to define custom logic for
fetching or refreshing access tokens.
Implementations§
Source§impl ExternallyManaged
impl ExternallyManaged
Sourcepub fn new(
refresh_function: impl Fn(AuthServer) -> Pin<Box<dyn Future<Output = Result<String, Box<dyn Error + Send + Sync>>> + Send>> + Send + Sync + 'static,
) -> Self
pub fn new( refresh_function: impl Fn(AuthServer) -> Pin<Box<dyn Future<Output = Result<String, Box<dyn Error + Send + Sync>>> + Send>> + Send + Sync + 'static, ) -> Self
Creates a new ExternallyManaged instance from a RefreshFunction.
Consider using ExternallyManaged::from_async, and ExternallyManaged::from_sync, if
they better fit your use case.
§Arguments
refresh_function- A function or closure that asynchronously refreshes a token.
§Example
use qcs_api_client_common::configuration::{AuthServer, ExternallyManaged, TokenError};
use std::future::Future;
use std::pin::Pin;
use std::boxed::Box;
use std::error::Error;
async fn example_refresh_function(_auth_server: AuthServer) -> Result<String, Box<dyn Error
+ Send + Sync>> {
Ok("new_token_value".to_string())
}
let token_manager = ExternallyManaged::new(|auth_server| Box::pin(example_refresh_function(auth_server)));Sourcepub fn from_async<F, Fut>(refresh_function: F) -> Self
pub fn from_async<F, Fut>(refresh_function: F) -> Self
Constructs a new ExternallyManaged instance using an async function or closure.
This method simplifies the creation of the ExternallyManaged instance by handling
the boxing and pinning of the future internally.
§Arguments
refresh_function- An async function or closure that returns aFuturewhich, when awaited, produces aResult<String, TokenError>.
§Example
use qcs_api_client_common::configuration::{AuthServer, ExternallyManaged, TokenError};
use tokio::runtime::Runtime;
use std::error::Error;
async fn example_refresh_function(_auth_server: AuthServer) -> Result<String, Box<dyn Error
+ Send + Sync>> {
Ok("new_token_value".to_string())
}
let token_manager = ExternallyManaged::from_async(example_refresh_function);
let rt = Runtime::new().unwrap();
rt.block_on(async {
match token_manager.request_access_token(&AuthServer::default()).await {
Ok(token) => println!("Token: {}", token),
Err(e) => println!("Failed to refresh token: {:?}", e),
}
});Sourcepub fn from_sync(
refresh_function: impl Fn(AuthServer) -> Result<String, Box<dyn Error + Send + Sync>> + Send + Sync + 'static,
) -> Self
pub fn from_sync( refresh_function: impl Fn(AuthServer) -> Result<String, Box<dyn Error + Send + Sync>> + Send + Sync + 'static, ) -> Self
Constructs a new ExternallyManaged instance using a synchronous function.
The synchronous function is wrapped in an async block to fit the expected signature.
§Arguments
refresh_function- A synchronous function that returns aResult<String, TokenError>.
§Example
use qcs_api_client_common::configuration::{AuthServer, ExternallyManaged, TokenError};
use tokio::runtime::Runtime;
use std::error::Error;
fn example_sync_refresh_function(_auth_server: AuthServer) -> Result<String, Box<dyn Error
+ Send + Sync>> {
Ok("sync_token_value".to_string())
}
let token_manager = ExternallyManaged::from_sync(example_sync_refresh_function);
let rt = Runtime::new().unwrap();
rt.block_on(async {
match token_manager.request_access_token(&AuthServer::default()).await {
Ok(token) => println!("Token: {}", token),
Err(e) => println!("Failed to refresh token: {:?}", e),
}
});Sourcepub async fn request_access_token(
&self,
auth_server: &AuthServer,
) -> Result<String, Box<dyn Error + Send + Sync>>
pub async fn request_access_token( &self, auth_server: &AuthServer, ) -> Result<String, Box<dyn Error + Send + Sync>>
Request an updated access token using the provided refresh function.
§Errors
Errors are propagated from the refresh function.
Trait Implementations§
Source§impl Clone for ExternallyManaged
impl Clone for ExternallyManaged
Source§fn clone(&self) -> ExternallyManaged
fn clone(&self) -> ExternallyManaged
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ExternallyManaged
impl Debug for ExternallyManaged
Source§impl From<ExternallyManaged> for OAuthGrant
impl From<ExternallyManaged> for OAuthGrant
Source§fn from(v: ExternallyManaged) -> Self
fn from(v: ExternallyManaged) -> Self
Source§impl PyClass for ExternallyManaged
impl PyClass for ExternallyManaged
Source§impl PyClassImpl for ExternallyManaged
impl PyClassImpl for ExternallyManaged
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§type ThreadChecker = SendablePyClass<ExternallyManaged>
type ThreadChecker = SendablePyClass<ExternallyManaged>
type Inventory = Pyo3MethodsInventoryForExternallyManaged
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny by default, and when you declare
#[pyclass(extends=PyDict)], it’s PyDict.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl PyClassNewTextSignature<ExternallyManaged> for PyClassImplCollector<ExternallyManaged>
impl PyClassNewTextSignature<ExternallyManaged> for PyClassImplCollector<ExternallyManaged>
fn new_text_signature(self) -> Option<&'static str>
Source§impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a ExternallyManaged
impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a ExternallyManaged
Source§impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a mut ExternallyManaged
impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a mut ExternallyManaged
Source§impl PyTypeInfo for ExternallyManaged
impl PyTypeInfo for ExternallyManaged
Source§type AsRefTarget = PyCell<ExternallyManaged>
type AsRefTarget = PyCell<ExternallyManaged>
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
Source§fn type_object(py: Python<'_>) -> &PyType
fn type_object(py: Python<'_>) -> &PyType
Source§fn is_type_of(object: &PyAny) -> bool
fn is_type_of(object: &PyAny) -> bool
object is an instance of this type or a subclass of this type.Source§fn is_exact_type_of(object: &PyAny) -> bool
fn is_exact_type_of(object: &PyAny) -> bool
object is an instance of this type.Auto Trait Implementations§
impl Freeze for ExternallyManaged
impl !RefUnwindSafe for ExternallyManaged
impl Send for ExternallyManaged
impl Sync for ExternallyManaged
impl Unpin for ExternallyManaged
impl !UnwindSafe for ExternallyManaged
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,
Source§impl<'a, T> FromPyObject<'a> for T
impl<'a, T> FromPyObject<'a> for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);