pub struct SphereRenderer<C, S>where
C: HasSphereContext<S> + 'static,
S: Storage + 'static,{ /* private fields */ }Expand description
SphereRenderer embodies all of the work needed to render a sphere graph to a workspace file system location. Starting from the “root” sphere, the renderer will efficiently queue work to concurrently render the sphere graph up to a maximum depth.
The renderer produces a file system structure that is approximated by this diagram:
/workspace_root/
├── foo.subtext
├── bar/
│ └── baz.subtext
├── @my-peer/ -> ./.sphere/peers/bafyabc...x987
├── @other-peer/ -> ./.sphere/peers/bafyabc...y654
└── .sphere/
├── identity # The sphere ID of the root sphere
├── version # Last rendered version of the root sphere
├── depth # Last rendered depth
├── slugs # Backward mapping of slugs to files; base64-encoded to escape
│ │ # special characters that may occur in a slug (such as '/')
│ ├── Zm9v -> ../../foo.subtext
│ └── YmFyL2Jheg -> ../../bar/baz.subtext
├── storage/ # Storage folder distinguishes the root sphere
│ └── ... # Implementation-specific e.g., Sled will have its own DB structure
├── content/ # Hard links to content that appears in peer spheres
│ ├── bafyabc...a123
│ ├── bafyabc...b456
│ ├── bafyabc...c789
│ └── ...
└── peers/
├── bafyabc...x987/
│ ├── identity
│ ├── version
│ ├── link_record # A valid link record for this peer at this version
│ └── mount/ # The virtual root where a peers files an links to thier
│ │ # peers are rendered
│ ├── their-foo.subtext -> ../../../content/bafyabc...b456
│ ├── @peer3 -> ../../../peers/bafyabc...y654/mount
│ └── @peer4 -> ../../../peers/bafyabc...z321/mount
├── bafyabc...y654/
│ ├── identity
│ ├── version
│ ├── link_record
│ └── mount/
│ └── ...
├── bafyabc...z321/
│ ├── identity
│ ├── version
│ ├── link_record
│ └── mount/
│ └── ...
└── ...Peers throughout the graph are rendered into a flat structure. Each version of a peer sphere gets its own unique directory, and the “mount” subfolder therein contains a virtual file system representation of that sphere’s contents and peers. The word “virtual” is used because all content and spheres within the mount are represented as symlinks. This enables maximum re-use of content across revisions of peers over time.
Note that since peers may re-appear in address books at different depths of graph traversal, it’s possible to appear to have rendered more deeply than the “maximum” render depth (when in fact an already-rendered peer is just being re-used).
Implementations§
Source§impl<C, S> SphereRenderer<C, S>where
C: HasSphereContext<S> + 'static,
S: Storage + 'static,
impl<C, S> SphereRenderer<C, S>where
C: HasSphereContext<S> + 'static,
S: Storage + 'static,
Sourcepub fn new(context: C, paths: Arc<SpherePaths>) -> Self
pub fn new(context: C, paths: Arc<SpherePaths>) -> Self
Construct a SphereRenderer for the given root HasSphereContext and initialized SpherePaths.
Sourcepub async fn render(
&self,
depth: Option<u32>,
force_full_render: bool,
) -> Result<()>
pub async fn render( &self, depth: Option<u32>, force_full_render: bool, ) -> Result<()>
Render the sphere graph up to the given depth; the renderer will attempt to render different edges from the root concurrently, efficiently and idempotently. If the specified render depth increases for a subsequent render, all rendered peers will be reset and rendered again (although the hard links to their content will remain unchanged).
Auto Trait Implementations§
impl<C, S> Freeze for SphereRenderer<C, S>where
C: Freeze,
impl<C, S> RefUnwindSafe for SphereRenderer<C, S>where
C: RefUnwindSafe,
S: RefUnwindSafe,
impl<C, S> Send for SphereRenderer<C, S>
impl<C, S> Sync for SphereRenderer<C, S>
impl<C, S> Unpin for SphereRenderer<C, S>
impl<C, S> UnwindSafe for SphereRenderer<C, S>where
C: UnwindSafe,
S: UnwindSafe,
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> FitForCBox for T
impl<T> FitForCBox for T
type CBoxWrapped = Box_<T>
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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