#[non_exhaustive]pub struct DevServer {
pub ip: IpAddr,
pub port: u16,
pub watch: Watch,
pub dist_dir: Option<PathBuf>,
pub pre_hooks: Vec<Box<dyn Hook>>,
pub command: Option<Command>,
pub post_hooks: Vec<Box<dyn Hook>>,
pub not_found_path: Option<PathBuf>,
/* private fields */
}Expand description
A simple HTTP server useful during development.
It can watch the source code for changes and restart a provided command.
Serve the file from the provided dist_dir at a given IP address
(127.0.0.1:8000 by default). An optional command can be provided to restart the build when
changes are detected using command, xtask or
cargo.
§Usage
use std::process;
use xtask_wasm::{
anyhow::Result,
clap,
};
#[derive(clap::Parser)]
enum Opt {
Start(xtask_wasm::DevServer),
Dist,
}
fn main() -> Result<()> {
let opt: Opt = clap::Parser::parse();
match opt {
Opt::Dist => todo!("build project"),
Opt::Start(dev_server) => {
log::info!("Starting the development server...");
dev_server
.xtask("dist")
.start()?;
}
}
Ok(())
}This adds a start subcommand that will run cargo xtask dist, watching for
changes in the workspace and serve the files in the default dist directory
(target/debug/dist) at the default IP address.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.ip: IpAddrIP address to bind. Default to 127.0.0.1.
port: u16Port number. Default to 8000.
watch: WatchWatch configuration for detecting file-system changes.
Controls which paths are watched, debounce timing, and other watch
behaviour. Watching is only active when at least one of pre_hooks,
command, or post_hooks is set; if none are provided the watch
thread is not started.
dist_dir: Option<PathBuf>Directory of all generated artifacts.
pre_hooks: Vec<Box<dyn Hook>>Commands executed before the main command when a change is detected.
command: Option<Command>Main command executed when a change is detected.
post_hooks: Vec<Box<dyn Hook>>Commands executed after the main command when a change is detected.
not_found_path: Option<PathBuf>Use another file path when the URL is not found.
Implementations§
Source§impl DevServer
impl DevServer
Sourcepub fn dist_dir(self, path: impl Into<PathBuf>) -> Self
pub fn dist_dir(self, path: impl Into<PathBuf>) -> Self
Set the directory for the generated artifacts.
The default is target/debug/dist.
Sourcepub fn pre(self, command: impl Hook + 'static) -> Self
pub fn pre(self, command: impl Hook + 'static) -> Self
Add a command to execute before the main command when a change is detected.
Sourcepub fn pres(
self,
commands: impl IntoIterator<Item = impl Hook + 'static>,
) -> Self
pub fn pres( self, commands: impl IntoIterator<Item = impl Hook + 'static>, ) -> Self
Add multiple commands to execute before the main command when a change is detected.
Sourcepub fn post(self, command: impl Hook + 'static) -> Self
pub fn post(self, command: impl Hook + 'static) -> Self
Add a command to execute after the main command when a change is detected.
Sourcepub fn posts(
self,
commands: impl IntoIterator<Item = impl Hook + 'static>,
) -> Self
pub fn posts( self, commands: impl IntoIterator<Item = impl Hook + 'static>, ) -> Self
Add multiple commands to execute after the main command when a change is detected.
Sourcepub fn command(self, command: Command) -> Self
pub fn command(self, command: Command) -> Self
Main command executed when a change is detected.
See xtask if you want to use an xtask command.
Sourcepub fn xtask(self, name: impl AsRef<str>) -> Self
pub fn xtask(self, name: impl AsRef<str>) -> Self
Name of the main xtask command that is executed when a change is detected.
See command to use an arbitrary command.
Sourcepub fn not_found_path(self, path: impl Into<PathBuf>) -> Self
pub fn not_found_path(self, path: impl Into<PathBuf>) -> Self
Use another file path when the URL is not found.
Sourcepub fn request_handler<F>(self, handler: F) -> Self
pub fn request_handler<F>(self, handler: F) -> Self
Pass a custom request handler to the dev server.
Trait Implementations§
Source§impl Args for DevServer
impl Args for DevServer
Source§fn augment_args<'b>(__clap_app: Command) -> Command
fn augment_args<'b>(__clap_app: Command) -> Command
Source§fn augment_args_for_update<'b>(__clap_app: Command) -> Command
fn augment_args_for_update<'b>(__clap_app: Command) -> Command
Command so it can instantiate self via
FromArgMatches::update_from_arg_matches_mut Read moreSource§impl CommandFactory for DevServer
impl CommandFactory for DevServer
Source§impl FromArgMatches for DevServer
impl FromArgMatches for DevServer
Source§fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
Source§fn from_arg_matches_mut(
__clap_arg_matches: &mut ArgMatches,
) -> Result<Self, Error>
fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches, ) -> Result<Self, Error>
Source§fn update_from_arg_matches(
&mut self,
__clap_arg_matches: &ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches, ) -> Result<(), Error>
ArgMatches to self.Source§fn update_from_arg_matches_mut(
&mut self,
__clap_arg_matches: &mut ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches, ) -> Result<(), Error>
ArgMatches to self.Source§impl Parser for DevServer
impl Parser for DevServer
Source§fn parse_from<I, T>(itr: I) -> Self
fn parse_from<I, T>(itr: I) -> Self
Source§fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
Source§fn update_from<I, T>(&mut self, itr: I)
fn update_from<I, T>(&mut self, itr: I)
Auto Trait Implementations§
impl Freeze for DevServer
impl !RefUnwindSafe for DevServer
impl !Send for DevServer
impl !Sync for DevServer
impl Unpin for DevServer
impl UnsafeUnpin for DevServer
impl !UnwindSafe for DevServer
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> 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