pub fn serve_site_with<T: ServeTransport>(
site_dir: &Path,
transport: &T,
) -> Result<(), SsgError>Expand description
Starts the dev server using a caller-supplied transport.
Extracted so test code can pass a no-op transport and still
exercise the surrounding glue (path validation, address
formatting). Production callers use serve_site which
delegates to HttpTransport.
§Errors
Returns an error if site_dir contains invalid UTF-8 or if the
underlying transport fails.
§Examples
use ssg::server::{serve_site_with, ServeTransport};
use ssg::SsgError;
use std::path::Path;
use std::cell::RefCell;
struct Recorder(RefCell<Vec<(String, String)>>);
impl ServeTransport for Recorder {
fn start(&self, addr: &str, root: &str) -> Result<(), SsgError> {
self.0.borrow_mut().push((addr.into(), root.into()));
Ok(())
}
}
let rec = Recorder(RefCell::new(vec![]));
serve_site_with(Path::new("public"), &rec).unwrap();
assert_eq!(rec.0.borrow().len(), 1);