pub struct StaticDocumentWriter { /* private fields */ }Expand description
Writes complete documents to route-derived index.html files.
Applications enumerate routes and provide page data; this writer owns the
filesystem mapping from each route to its static output path. This
server-side API is omitted from wasm32 builds.
Implementations§
Source§impl StaticDocumentWriter
impl StaticDocumentWriter
Sourcepub fn new(output_directory: impl Into<PathBuf>) -> StaticDocumentWriter
pub fn new(output_directory: impl Into<PathBuf>) -> StaticDocumentWriter
Creates a writer rooted at output_directory.
Sourcepub fn from_env() -> Result<StaticDocumentWriter, ViewError>
pub fn from_env() -> Result<StaticDocumentWriter, ViewError>
Creates a writer using the output directory supplied by serenade-ssg.
§Errors
Returns an error when the environment variable is missing or empty.
Sourcepub fn output_path(&self, route: &str) -> Result<PathBuf, ViewError>
pub fn output_path(&self, route: &str) -> Result<PathBuf, ViewError>
Resolves a normalized URL route to its static index.html path.
/ maps to <output>/index.html; /about and /about/ map to
<output>/about/index.html. Query strings, fragments, and unsafe path
segments are rejected.
§Errors
Returns an error when route is not a safe absolute URL path.
Sourcepub fn write(
&self,
route: &str,
document: RenderedDocument,
) -> Result<PathBuf, ViewError>
pub fn write( &self, route: &str, document: RenderedDocument, ) -> Result<PathBuf, ViewError>
Writes a rendered document at the static path for route.
Route directories below the output directory are created one level at a
time and must be real directories: a symbolic link there is rejected, so
a document is never written outside the output directory. The document
is written to a uniquely named temporary file that then replaces
index.html (on Unix and Windows), so an existing symbolic link is
replaced instead of written through and concurrent writes of the same
route do not interfere; the last completed write wins.
§Errors
Returns an error when the route is unsafe, a route directory is a symbolic link or not a directory, or the document cannot be written.
Trait Implementations§
Source§impl Clone for StaticDocumentWriter
impl Clone for StaticDocumentWriter
Source§fn clone(&self) -> StaticDocumentWriter
fn clone(&self) -> StaticDocumentWriter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StaticDocumentWriter
impl Debug for StaticDocumentWriter
impl Eq for StaticDocumentWriter
Source§impl PartialEq for StaticDocumentWriter
impl PartialEq for StaticDocumentWriter
impl StructuralPartialEq for StaticDocumentWriter
Auto Trait Implementations§
impl Forget for StaticDocumentWriter
impl Freeze for StaticDocumentWriter
impl Move for StaticDocumentWriter
impl RefUnwindSafe for StaticDocumentWriter
impl Send for StaticDocumentWriter
impl Sync for StaticDocumentWriter
impl Unpin for StaticDocumentWriter
impl UnsafeUnpin for StaticDocumentWriter
impl UnwindSafe for StaticDocumentWriter
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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