Skip to main content

StaticDocumentWriter

Struct StaticDocumentWriter 

Source
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

Source

pub fn new(output_directory: impl Into<PathBuf>) -> Self

Creates a writer rooted at output_directory.

Source

pub fn from_env() -> Result<Self, ViewError>

Creates a writer using the output directory supplied by serenade-ssg.

§Errors

Returns an error when the environment variable is missing or empty.

Source

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.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for StaticDocumentWriter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for StaticDocumentWriter

Source§

impl PartialEq for StaticDocumentWriter

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for StaticDocumentWriter

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.