cargo_msrv/context/
set.rs1use crate::cli::{CargoMsrvOpts, SubCommand};
2use crate::context::{EnvironmentContext, RustReleasesContext};
3use crate::error::CargoMSRVError;
4use crate::manifest::bare_version::BareVersion;
5use std::convert::{TryFrom, TryInto};
6
7#[derive(Debug)]
8pub struct SetContext {
9 pub msrv: BareVersion,
11
12 pub rust_releases: RustReleasesContext,
14
15 pub environment: EnvironmentContext,
17}
18
19impl TryFrom<CargoMsrvOpts> for SetContext {
20 type Error = CargoMSRVError;
21
22 fn try_from(opts: CargoMsrvOpts) -> Result<Self, Self::Error> {
23 let CargoMsrvOpts {
24 shared_opts,
25 subcommand,
26 ..
27 } = opts;
28
29 let set_opts = match subcommand {
30 SubCommand::Set(opts) => opts,
31 _ => unreachable!("This should never happen. The subcommand is not `set`!"),
32 };
33
34 let environment = (&shared_opts).try_into()?;
35
36 Ok(Self {
37 msrv: set_opts.msrv,
38 rust_releases: set_opts.rust_releases_opts.into(),
39 environment,
40 })
41 }
42}