Skip to main content

File

Struct File 

Source
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

Source

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.

Source

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();
})
Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,