pub struct File { /* private fields */ }Expand description
A file on disk which stores, or can store, a JWT for authenticating with SpacetimeDB.
The file does not necessarily exist or store credentials.
If the credentials have been stored previously, they can be accessed with File::load.
New credentials can be saved to disk with File::save.
Implementations§
Source§impl File
impl File
Sourcepub fn new(key: impl Into<String>) -> Self
pub fn new(key: impl Into<String>) -> Self
Get a handle on a file which stores a SpacetimeDB [Identity] and its private access token.
This method does not create the file or check that it exists.
Distinct applications running as the same user on the same machine
may share [Identity]/token pairs by supplying the same key.
Users who desire distinct credentials for their application
should supply a unique key per application.
No additional namespacing is provided to tie the stored token
to a particular SpacetimeDB instance or cluster.
Users who intend to connect to multiple instances or clusters
should use a distinct key per cluster.
Sourcepub fn save(self, token: impl Into<String>) -> Result<(), CredentialFileError>
pub fn save(self, token: impl Into<String>) -> Result<(), CredentialFileError>
Store the provided token to disk in the file referred to by self.
Future calls to Self::load on a File with the same key can retrieve the token.
Expected usage is to call this from a [super::DbConnectionBuilder::on_connect] callback.
DbConnection::builder()
.on_connect(|_ctx, _identity, token| {
credentials::File::new("my_app").save(token).unwrap();
})Sourcepub fn load(self) -> Result<Option<String>, CredentialFileError>
pub fn load(self) -> Result<Option<String>, CredentialFileError>
Load a saved token from disk in the file referred to by self,
if they have previously been stored by Self::save.
Returns Err if I/O fails,
None if credentials have not previously been stored,
or Some if credentials are successfully loaded from disk.
After unwrapping the Result, the returned Option can be passed to
[super::DbConnectionBuilder::with_token].
DbConnection::builder()
.with_token(credentials::File::new("my_app").load().unwrap())Auto Trait Implementations§
impl Freeze for File
impl RefUnwindSafe for File
impl Send for File
impl Sync for File
impl Unpin for File
impl UnsafeUnpin for File
impl UnwindSafe for File
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> 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