Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a Config struct and an "init_with" method to Bastion to use it,…
… updated the getting started examples to use it and fixed markdown issues.
- Loading branch information
Showing
8 changed files
with
235 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
#[derive(Default, Debug, Clone)] | ||
/// The configuration that should be used to initialize the | ||
/// system using [`Bastion::init_with`]. | ||
/// | ||
/// The default behaviors are the following: | ||
/// - All backtraces are shown (see [`Config::show_backtraces`]). | ||
/// | ||
/// # Example | ||
/// | ||
/// ```rust | ||
/// use bastion::prelude::*; | ||
/// | ||
/// fn main() { | ||
/// let config = Config::new() | ||
/// .show_backtraces(); | ||
/// | ||
/// Bastion::init_with(config); | ||
/// | ||
/// // You can now use bastion... | ||
/// # | ||
/// # Bastion::start(); | ||
/// # Bastion::stop(); | ||
/// # Bastion::block_until_stopped(); | ||
/// } | ||
/// ``` | ||
/// | ||
/// [`Bastion::init_with`]: struct.Bastion.html#method.init_with | ||
pub struct Config { | ||
backtraces: Backtraces, | ||
} | ||
|
||
#[derive(PartialEq, Eq, Debug, Clone)] | ||
pub(crate) enum Backtraces { | ||
/// Shows all backtraces, like an application without | ||
/// Bastion would. | ||
Show, | ||
// TODO: Catch, | ||
/// Hides all backtraces. | ||
Hide, | ||
} | ||
|
||
impl Config { | ||
/// Creates a new configuration with the following default | ||
/// behaviors: | ||
/// - All backtraces are shown (see [`Config::show_backtraces`]). | ||
/// | ||
/// [`Config::show_backtraces`]: #method.show_backtraces | ||
pub fn new() -> Self { | ||
Config::default() | ||
} | ||
|
||
/// Makes Bastion show all backtraces, like an application | ||
/// without it would. This can be useful when trying to | ||
/// debug children panicking. | ||
/// | ||
/// Note that this is the default behavior. | ||
/// | ||
/// # Example | ||
/// | ||
/// ```rust | ||
/// use bastion::prelude::*; | ||
/// | ||
/// fn main() { | ||
/// let config = Config::new() | ||
/// .show_backtraces(); | ||
/// | ||
/// Bastion::init_with(config); | ||
/// | ||
/// // You can now use bastion and it will show you the | ||
/// // backtraces of panics... | ||
/// # | ||
/// # Bastion::start(); | ||
/// # Bastion::stop(); | ||
/// # Bastion::block_until_stopped(); | ||
/// } | ||
/// ``` | ||
pub fn show_backtraces(mut self) -> Self { | ||
self.backtraces = Backtraces::show(); | ||
self | ||
} | ||
|
||
/// Makes Bastion hide all backtraces. | ||
/// | ||
/// Note that the default behavior is to show all backtraces | ||
/// (see [`Config::show_backtraces`]). | ||
/// | ||
/// # Example | ||
/// | ||
/// ```rust | ||
/// use bastion::prelude::*; | ||
/// | ||
/// fn main() { | ||
/// let config = Config::new() | ||
/// .hide_backtraces(); | ||
/// | ||
/// Bastion::init_with(config); | ||
/// | ||
/// // You can now use bastion and no panic backtraces | ||
/// // will be shown... | ||
/// # | ||
/// # Bastion::start(); | ||
/// # Bastion::stop(); | ||
/// # Bastion::block_until_stopped(); | ||
/// } | ||
/// ``` | ||
/// | ||
/// [`Config::show_backtraces`]: #method.show_backtraces | ||
pub fn hide_backtraces(mut self) -> Self { | ||
self.backtraces = Backtraces::hide(); | ||
self | ||
} | ||
|
||
pub(crate) fn backtraces(&self) -> &Backtraces { | ||
&self.backtraces | ||
} | ||
} | ||
|
||
impl Backtraces { | ||
fn show() -> Self { | ||
Backtraces::Show | ||
} | ||
|
||
fn hide() -> Self { | ||
Backtraces::Hide | ||
} | ||
|
||
pub(crate) fn is_hide(&self) -> bool { | ||
self == &Backtraces::Hide | ||
} | ||
} | ||
|
||
impl Default for Backtraces { | ||
fn default() -> Self { | ||
Backtraces::Show | ||
} | ||
} |
Oops, something went wrong.