Skip to main content

LiveServer

Struct LiveServer 

Source
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

Source

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}
Source

pub fn static_config(cfg: Config, dir: impl Into<PathBuf>) -> Self

serve a blog in the given directory with a static config

Source

pub fn without_refresh(self) -> Self

disable autorefresh

Source

pub fn listen(&self, port: impl Into<Option<u16>>) -> Result<()>

serve forever on the current thread

Source

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§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V