use std::fmt;
use std::fmt::Formatter;
pub use scope::{Marker, Scope, ScopeCounter, ScopeGenerator, SupplyScopeGenerator};
#[cfg(test)]
pub use scope::TestScopeGenerator;
pub use auxiliary_output::{
AuxiliaryOutput, Destination, Item as AuxiliaryOutputItem, MsrvKind, ToolchainFileKind,
};
pub use check_method::{CheckMethod, Method};
pub use check_result::CheckResult;
pub use check_toolchain::CheckToolchain;
pub use fetch_index::FetchIndex;
pub use meta::Meta;
pub use progress::Progress;
pub use search_method::FindMsrv;
pub use setup_toolchain::SetupToolchain;
pub use subcommand_init::SubcommandInit;
pub use subcommand_result::SubcommandResult;
pub use termination::TerminateWithFailure;
pub use unable_to_confirm_valid_release_version::UnableToConfirmValidReleaseVersion;
pub use types::{
find_result::FindResult, list_result::ListResult, set_result::SetResult,
show_result::ShowResult, verify_result::VerifyResult,
};
mod scope;
mod shared;
mod types;
mod auxiliary_output;
mod check_method;
mod check_result;
mod check_toolchain;
mod fetch_index;
mod meta;
mod progress;
mod search_method;
mod setup_toolchain;
mod subcommand_init;
mod subcommand_result;
mod termination;
mod unable_to_confirm_valid_release_version;
#[derive(Clone, Debug, PartialEq, serde::Serialize)]
#[serde(rename_all = "snake_case")]
pub struct Event {
#[serde(flatten)]
message: Message,
#[serde(skip_serializing_if = "Option::is_none")]
scope: Option<Scope>,
}
impl Event {
#[cfg(test)]
pub(crate) fn unscoped(message: Message) -> Self {
Self {
message,
scope: None,
}
}
#[cfg(test)]
pub(crate) fn scoped(message: Message, scope: Scope) -> Self {
Self {
message,
scope: Some(scope),
}
}
pub fn message(&self) -> &Message {
&self.message
}
pub fn into_scoped(self, generator: &impl ScopeGenerator) -> (Self, Self) {
let (start_scope, end_scope) = generator.generate();
let (mut start_event, mut end_event) = (self.clone(), self);
start_event.scope = Some(start_scope);
end_event.scope = Some(end_scope);
(start_event, end_event)
}
pub fn is_scope_start(&self) -> bool {
matches!(
self.scope,
None | Some(Scope {
id: _,
marker: Marker::Start
})
)
}
}
#[derive(Clone, Debug, PartialEq, serde::Serialize)]
#[serde(rename_all = "snake_case")]
#[serde(tag = "type")]
pub enum Message {
Meta(Meta),
FetchIndex(FetchIndex), UnableToConfirmValidReleaseVersion(UnableToConfirmValidReleaseVersion),
CheckToolchain(CheckToolchain),
SetupToolchain(SetupToolchain),
CheckMethod(CheckMethod),
CheckResult(CheckResult),
AuxiliaryOutput(AuxiliaryOutput),
FindMsrv(FindMsrv),
Progress(Progress),
SubcommandInit(SubcommandInit),
SubcommandResult(SubcommandResult),
TerminateWithFailure(TerminateWithFailure),
}
impl From<Message> for Event {
fn from(message: Message) -> Self {
Event {
message,
scope: None,
}
}
}
impl fmt::Display for Event {
fn fmt(&self, _f: &mut Formatter<'_>) -> fmt::Result {
Ok(())
}
}
impl fmt::Display for Message {
fn fmt(&self, _f: &mut Formatter<'_>) -> fmt::Result {
Ok(())
}
}