#[non_exhaustive]pub struct DevServer {
pub ip: IpAddr,
pub port: u16,
pub watch: Watch,
pub command: Option<Command>,
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.
Get the files at watch_path and serve them 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.
§Usage
use std::process;
use xtask_wasm::{
anyhow::Result,
clap,
default_dist_dir,
};
#[derive(clap::Parser)]
enum Opt {
Start(xtask_wasm::DevServer),
Dist,
}
fn main() -> Result<()> {
let opt: Opt = clap::Parser::parse();
match opt {
Opt::Start(mut dev_server) => {
log::info!("Starting the development server...");
dev_server.arg("dist").start(default_dist_dir(false))?;
}
Opt::Dist => todo!("build project"),
}
Ok(())
}Add 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 for non-release) at a given 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: Watch§command: Option<Command>Command executed 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 command(self, command: Command) -> Self
pub fn command(self, command: Command) -> Self
Set the command that is executed when a change is detected.
Sourcepub fn arg<S: AsRef<OsStr>>(self, arg: S) -> Self
pub fn arg<S: AsRef<OsStr>>(self, arg: S) -> Self
Adds an argument to pass to the command executed when changes are detected.
This will use the xtask command by default.
Sourcepub fn args<I, S>(self, args: I) -> Self
pub fn args<I, S>(self, args: I) -> Self
Adds multiple arguments to pass to the command executed when changes are detected.
This will use the xtask command by default.
Sourcepub fn not_found(self, path: impl Into<PathBuf>) -> Self
pub fn not_found(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