pub struct SphereContext<S>where
    S: Storage + 'static,{ /* private fields */ }
Expand description

A SphereContext is an accessor construct over locally replicated sphere data. It embodies both the storage layer that contains the sphere’s data as the information needed to verify a user’s intended level of access to it (e.g., local key material and ucan::Ucan-based authorization). Additionally, the SphereContext maintains a reference to an API Client that may be initialized as the network becomes available.

All interactions that pertain to a sphere, including reading or writing its contents and syncing with a gateway, flow through the SphereContext.

Implementations§

source§

impl<S> SphereContext<S>where S: Storage,

source

pub async fn new( sphere_identity: Did, author: Author<SphereContextKey>, db: SphereDb<S>, origin_sphere_identity: Option<Did> ) -> Result<Self>

Instantiate a new SphereContext given a sphere Did, an Author, a SphereDb and an optional origin sphere Did. The origin sphere Did is intended to signify whether the SphereContext is a local sphere, or a global sphere that is being visited by a local author. In most cases, a SphereContext with some value set as the origin sphere Did will be read-only.

source

pub async fn to_visitor(&self, peer_identity: &Did) -> Result<Self>

Clone this SphereContext, setting the sphere identity to a peer’s Did

source

pub async fn with_author( &self, author: &Author<SphereContextKey> ) -> Result<SphereContext<S>>

Clone this SphereContext, replacing the Author with the provided one

source

pub async fn traverse_by_identity( &self, _sphere_identity: &Did ) -> Result<SphereContext<S>>

Given a Did of a sphere, produce a SphereContext backed by the same credentials and storage primitives as this one, but that accesses the sphere referred to by the provided Did.

source

pub fn identity(&self) -> &Did

The identity of the sphere

source

pub async fn gateway_identity(&self) -> Result<Did>

The identity of the gateway sphere in use during this session, if any; note that this will cause a request to be made to a gateway if no handshake has yet occurred.

source

pub async fn version(&self) -> Result<Link<MemoIpld>>

The CID of the most recent local version of this sphere

source

pub fn author(&self) -> &Author<SphereContextKey>

The Author who is currently accessing the sphere

source

pub async fn access(&self) -> Result<Access>

The Access level that the configured Author has relative to the sphere that this SphereContext refers to.

source

pub fn did_parser_mut(&mut self) -> &mut DidParser

Get a mutable reference to the DidParser used in this SphereContext

source

pub async fn configure_gateway_url(&mut self, url: Option<&Url>) -> Result<()>

Sets or unsets the gateway URL that points to the gateway API that the sphere will use when it is syncing.

source

pub fn db(&self) -> &SphereDb<S>

Get the SphereDb instance that manages the current sphere’s block space and persisted configuration.

source

pub fn db_mut(&mut self) -> &mut SphereDb<S>

Get a mutable reference to the SphereDb instance that manages the current sphere’s block space and persisted configuration.

source

pub fn mutation(&self) -> &SphereMutation

Get a read-only reference to the underlying SphereMutation that this SphereContext is tracking

source

pub fn mutation_mut(&mut self) -> &mut SphereMutation

Get a mutable reference to the underlying SphereMutation that this SphereContext is tracking

source

pub async fn sphere(&self) -> Result<Sphere<SphereDb<S>>>

Get a Sphere view over the current sphere’s latest revision. This view offers lower-level access than HasSphereContext, but includes affordances to help tranversing and manipulating IPLD structures that are more convenient than working directly with raw data.

source

pub async fn client(&self) -> Result<Arc<Client<SphereContextKey, SphereDb<S>>>>

Get a Client that will interact with a configured gateway (if a URL for one has been configured). This will initialize a Client if one is not already intialized, and will fail if the Client is unable to verify the identity of the gateway or otherwise connect to it.

Trait Implementations§

source§

impl<S> Clone for SphereContext<S>where S: Storage + 'static,

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<S> !RefUnwindSafe for SphereContext<S>

§

impl<S> Send for SphereContext<S>

§

impl<S> Sync for SphereContext<S>

§

impl<S> Unpin for SphereContext<S>where <S as Storage>::BlockStore: Unpin, <S as Storage>::KeyValueStore: Unpin,

§

impl<S> !UnwindSafe for SphereContext<S>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> References<RawCodec> for T

source§

fn references<R, E>(_c: RawCodec, _r: &mut R, _set: &mut E) -> Result<(), Error>where R: Read, E: Extend<Cid<64>>,

Scrape the references from an impl Read. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

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

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<S> ConditionalSend for Swhere S: Send,

source§

impl<S> ConditionalSync for Swhere S: Send + Sync,

source§

impl<S> TargetConditionalSendSync for Swhere S: Send + Sync,

source§

impl<T> TryBundleSendSync for Twhere T: Send + Sync,

source§

impl<U> UcanStoreConditionalSend for Uwhere U: Send,

source§

impl<U> UcanStoreConditionalSendSync for Uwhere U: Send + Sync,