pub struct Auth {
pub token: Option<SecretString>,
}Expand description
Token authentication for Figshare API requests.
Fields§
§token: Option<SecretString>API token used for authenticated requests, or None for anonymous access.
Implementations§
Source§impl Auth
impl Auth
Sourcepub const TOKEN_ENV_VAR: &'static str = "FIGSHARE_TOKEN"
pub const TOKEN_ENV_VAR: &'static str = "FIGSHARE_TOKEN"
Standard environment variable for a Figshare API token.
Sourcepub fn new(token: impl Into<String>) -> Self
pub fn new(token: impl Into<String>) -> Self
Creates a new authentication wrapper from a raw token string.
Sourcepub fn anonymous() -> Self
pub fn anonymous() -> Self
Creates an anonymous authentication wrapper for public API calls.
§Examples
use figshare_rs::Auth;
let auth = Auth::anonymous();
assert!(auth.is_anonymous());Sourcepub fn from_env() -> Result<Self, FigshareError>
pub fn from_env() -> Result<Self, FigshareError>
Reads a Figshare API token from Self::TOKEN_ENV_VAR.
§Errors
Returns an error if the environment variable is missing or invalid.
Sourcepub fn from_env_var(name: &str) -> Result<Self, FigshareError>
pub fn from_env_var(name: &str) -> Result<Self, FigshareError>
Reads a Figshare API token from a custom environment variable.
§Errors
Returns an error if the environment variable is missing or invalid.
Sourcepub fn is_anonymous(&self) -> bool
pub fn is_anonymous(&self) -> bool
Returns whether this authentication wrapper is anonymous.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Auth
impl RefUnwindSafe for Auth
impl Send for Auth
impl Sync for Auth
impl Unpin for Auth
impl UnsafeUnpin for Auth
impl UnwindSafe for Auth
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
Mutably borrows from an owned value. Read more