#![deny(missing_docs)]
#![forbid(unsafe_code)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#[cfg(feature = "browser")]
#[cfg_attr(docsrs, doc(cfg(feature = "browser")))]
mod csr;
#[cfg(feature = "browser")]
#[cfg_attr(docsrs, doc(cfg(feature = "browser")))]
mod hydrate;
mod ssr;
#[cfg(feature = "browser")]
pub use csr::*;
use futures::Stream;
#[cfg(feature = "browser")]
pub use hydrate::*;
use serde::{Deserialize, Serialize};
pub use ssr::*;
use std::{fmt::Debug, future::Future, pin::Pin};
use throw_error::{Error, ErrorId};
pub type PinnedFuture<T> = Pin<Box<dyn Future<Output = T> + Send + Sync>>;
pub type PinnedLocalFuture<T> = Pin<Box<dyn Future<Output = T>>>;
pub type PinnedStream<T> = Pin<Box<dyn Stream<Item = T> + Send + Sync>>;
#[derive(
Clone, Debug, PartialEq, Eq, Hash, Default, Deserialize, Serialize,
)]
#[serde(transparent)]
pub struct SerializedDataId(usize);
impl SerializedDataId {
pub fn new(id: usize) -> Self {
SerializedDataId(id)
}
pub fn into_inner(self) -> usize {
self.0
}
}
impl From<SerializedDataId> for ErrorId {
fn from(value: SerializedDataId) -> Self {
value.0.into()
}
}
pub trait SharedContext: Debug {
fn is_browser(&self) -> bool;
fn next_id(&self) -> SerializedDataId;
fn write_async(&self, id: SerializedDataId, fut: PinnedFuture<String>);
fn read_data(&self, id: &SerializedDataId) -> Option<String>;
fn await_data(&self, id: &SerializedDataId) -> Option<String>;
fn pending_data(&self) -> Option<PinnedStream<String>>;
fn during_hydration(&self) -> bool;
fn hydration_complete(&self);
fn get_is_hydrating(&self) -> bool;
fn set_is_hydrating(&self, is_hydrating: bool);
fn take_errors(&self) -> Vec<(SerializedDataId, ErrorId, Error)>;
fn errors(&self, boundary_id: &SerializedDataId) -> Vec<(ErrorId, Error)>;
fn seal_errors(&self, boundary_id: &SerializedDataId);
fn register_error(
&self,
error_boundary: SerializedDataId,
error_id: ErrorId,
error: Error,
);
fn defer_stream(&self, wait_for: PinnedFuture<()>);
fn await_deferred(&self) -> Option<PinnedFuture<()>>;
fn set_incomplete_chunk(&self, id: SerializedDataId);
fn get_incomplete_chunk(&self, id: &SerializedDataId) -> bool;
}