Struct noosphere_fs::SphereFs

source ·
pub struct SphereFs<S, K>where
    S: Storage,
    K: KeyMaterial + Clone + 'static,{ /* private fields */ }
Expand description

SphereFs: An FS-like abstraction over Noosphere content.

A sphere implements a flat namespace that maps strings to CIDs, which in turn refer to the sphere owner’s content. However, it is not particularly convenient for users to think of their content as organized around these primitives. The SphereFs interface offers a familiar, relatively high-level interface for operation on sphere content.

Implementations§

source§

impl<S, K> SphereFs<S, K>where S: Storage, K: KeyMaterial + Clone + 'static,

source

pub fn identity(&self) -> &str

Get the DID identity of the sphere that this FS view is reading from and writing to

source

pub fn revision(&self) -> &Cid

The CID revision of the sphere that this FS view is reading from and writing to

source

pub fn to_sphere(&self) -> Sphere<S::BlockStore>

Get a data view into the sphere at the current revision

source

pub async fn latest( sphere_identity: &Did, author: &Author<K>, db: &SphereDb<S> ) -> Result<SphereFs<S, K>>

Create an FS view into the latest revision found in the provided sphere reference storage

source

pub async fn at( sphere_identity: &Did, sphere_revision: &Cid, author: &Author<K>, db: &SphereDb<S> ) -> Result<SphereFs<S, K>>

Create an FS view into the sphere data at a specific revision; note that writes to this view will “fork” history and update the sphere reference to point to the fork.

source

pub async fn rewind(&mut self) -> Result<Option<Cid>>

Rewind the view to point to the version of the sphere just prior to this one in the edit chronology. If there was a previous version to rewind to then the returned Option has the CID of the revision, otherwise if the current version is the oldest one it is None.

source

pub async fn exists(&self, slug: &str) -> Result<bool>

Returns true if the content identitifed by slug exists in the sphere at the current revision.

source

pub async fn read( &self, slug: &str ) -> Result<Option<SphereFile<impl AsyncRead>>>

Read a file that is associated with a given slug at the revision of the sphere that this view is pointing to. Note that “contents” are AsyncRead, and content bytes won’t be read until contents is polled.

source

pub async fn write<R: AsyncRead + Unpin>( &mut self, slug: &str, content_type: &str, value: R, additional_headers: Option<Vec<(String, String)>> ) -> Result<Cid>

Write to a slug in the sphere. In order to commit the change to the sphere, you must call save. You can buffer multiple writes before saving.

The returned CID is a link to the memo for the newly added content.

Similar to write, but instead of generating blocks from some provided bytes, the caller provides a CID of an existing DAG in storage. That CID is used as the body of a Memo that is written to the specified slug, and the CID of the memo is returned.

source

pub async fn remove(&mut self, slug: &str) -> Result<Option<Cid>>

Unlinks a slug from the content space. Note that this does not remove the blocks that were previously associated with the content found at the given slug, because they will still be available at an earlier revision of the sphere. In order to commit the change, you must save. Note that this call is a no-op if there is no matching slug linked in the sphere.

The returned value is the CID previously associated with the slug, if any.

source

pub async fn save( &mut self, additional_headers: Option<Vec<(String, String)>> ) -> Result<Cid>

Commits a series of writes to the sphere. In addition to commiting new content to the sphere and block storage, this method:

  • Creates a new revision based on the one that this FS view points to
  • Signs the new revision with provided key material
  • Updates this FS view to point to the new revision

The new revision CID of the sphere is returned.

source

pub async fn list(&self) -> BTreeSet<String>

Get a BTreeSet whose members are all the slugs that have values as of this version of the sphere. Note that the full space of slugs may be very large; for a more space-efficient approach, use SphereFs::stream or SphereFs::into_stream to incrementally access all slugs in the sphere.

This method is forgiving of missing or corrupted data, and will yield an incomplete set of links in the case that some or all links are not able to be accessed.

source

pub async fn changes(&self, since: Option<&Cid>) -> BTreeSet<String>

Get a BTreeSet whose members are all the slugs whose values have changed at least once since the provided version of the sphere (exclusive of the provided version; use None to get all slugs changed since the beginning of the sphere’s history).

This method is forgiving of missing or corrupted history, and will yield an incomplete set of changes in the case that some or all changes are not able to be accessed.

Note that this operation will scale in memory consumption and duration proportionally to the size of the sphere and the length of its history. For a more efficient method of accessing changes, consider using SphereFs::change_stream instead.

source

pub fn stream<'a>( &'a self ) -> impl Stream<Item = Result<(String, SphereFile<impl AsyncRead + 'a>)>>

Get a stream that yields every slug in the namespace along with its corresponding SphereFile. This is useful for iterating over sphere content incrementally without having to load the entire index into memory at once.

source

pub fn into_stream( self ) -> impl Stream<Item = Result<(String, SphereFile<impl AsyncRead>)>>

Same as stream, but consumes the SphereFs. This is useful in cases where it would otherwise be necessary to borrow a reference to SphereFs for a static lifetime.

source

pub fn change_stream<'a>( &'a self, since: Option<&'a Cid> ) -> impl Stream<Item = Result<(Cid, BTreeSet<String>)>> + 'a

Get a stream that yields the set of slugs that changed at each revision of the backing sphere, up to but excluding an optional CID. To stream the entire history, pass None as the parameter.

Trait Implementations§

source§

impl<S, K> Clone for SphereFs<S, K>where S: Storage, K: KeyMaterial + Clone + '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, K> RefUnwindSafe for SphereFs<S, K>where K: RefUnwindSafe, <S as Storage>::BlockStore: RefUnwindSafe, <S as Storage>::KeyValueStore: RefUnwindSafe,

§

impl<S, K> Send for SphereFs<S, K>

§

impl<S, K> Sync for SphereFs<S, K>

§

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

§

impl<S, K> UnwindSafe for SphereFs<S, K>where K: UnwindSafe, <S as Storage>::BlockStore: UnwindSafe, <S as Storage>::KeyValueStore: UnwindSafe,

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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · 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>,

const: unstable · 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 = mem::align_of::<T>()

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<T> 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.
const: unstable · 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.
const: unstable · 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<T> BlockStoreSend for Twhere T: Send,

source§

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

source§

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

source§

impl<T> KeyValueStoreSend for Twhere T: Send,

source§

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

source§

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

source§

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

§

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,

source§

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