pub struct LiveServer { /* private fields */ }Expand description
serve a raw::Config, fresh from the disk
this will almost always live behind an Arc, so expect to be .clone()ing a lot!
this autorefreshes by default.
that works by hosting a new url somewhere under /.breb-sys/ (it’s long and random to avoid collisions)
with a version number derived from scanning and hashing the metadata of the input directory.
a bit of javascript injected into any html page to ping that, check if the value changes, and refresh.
Implementations§
Source§impl LiveServer
impl LiveServer
Sourcepub fn live_config(cfg: impl Into<PathBuf>, dir: impl Into<PathBuf>) -> Self
pub fn live_config(cfg: impl Into<PathBuf>, dir: impl Into<PathBuf>) -> Self
serve a blog in the given directory with the given config
Examples found in repository?
examples/simple/main.rs (line 17)
5fn main() {
6 let port = env::args().nth(1)
7 .map(|s| s.parse::<u16>())
8 .transpose()
9 .expect("that port wasn't an integer");
10
11 let Ok(manifest_dir) = env::var("CARGO_MANIFEST_DIR") else {
12 panic!("you need to run this as an example with cargo.");
13 };
14 let manifest_dir = Path::new(&manifest_dir);
15 let example_dir = manifest_dir.join("examples/simple/");
16
17 let in_bg = LiveServer::live_config(example_dir.join("breb.yml"), example_dir)
18 .listen_background(port)
19 .expect("failed to start server");
20 println!("server is listening on http://{}", in_bg.address);
21 // wait for ctrl+c
22 loop {
23 thread::sleep(Duration::MAX);
24 }
25}Sourcepub fn static_config(cfg: Config, dir: impl Into<PathBuf>) -> Self
pub fn static_config(cfg: Config, dir: impl Into<PathBuf>) -> Self
serve a blog in the given directory with a static config
Sourcepub fn without_refresh(self) -> Self
pub fn without_refresh(self) -> Self
disable autorefresh
Sourcepub fn listen(&self, port: impl Into<Option<u16>>) -> Result<()>
pub fn listen(&self, port: impl Into<Option<u16>>) -> Result<()>
serve forever on the current thread
Sourcepub fn listen_background(
&self,
port: impl Into<Option<u16>>,
) -> Result<BackgroundServer>
pub fn listen_background( &self, port: impl Into<Option<u16>>, ) -> Result<BackgroundServer>
serve until stopped on a background thread
Examples found in repository?
examples/simple/main.rs (line 18)
5fn main() {
6 let port = env::args().nth(1)
7 .map(|s| s.parse::<u16>())
8 .transpose()
9 .expect("that port wasn't an integer");
10
11 let Ok(manifest_dir) = env::var("CARGO_MANIFEST_DIR") else {
12 panic!("you need to run this as an example with cargo.");
13 };
14 let manifest_dir = Path::new(&manifest_dir);
15 let example_dir = manifest_dir.join("examples/simple/");
16
17 let in_bg = LiveServer::live_config(example_dir.join("breb.yml"), example_dir)
18 .listen_background(port)
19 .expect("failed to start server");
20 println!("server is listening on http://{}", in_bg.address);
21 // wait for ctrl+c
22 loop {
23 thread::sleep(Duration::MAX);
24 }
25}Auto Trait Implementations§
impl !RefUnwindSafe for LiveServer
impl !UnwindSafe for LiveServer
impl Freeze for LiveServer
impl Send for LiveServer
impl Sync for LiveServer
impl Unpin for LiveServer
impl UnsafeUnpin for LiveServer
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
Converts
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> ⓘ
Converts
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