git-next/crates/config/src/forge_details.rs
Paul Campbell d70baa4350
All checks were successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
refactor(config): more derive_more replacing boilerplate
2024-05-15 07:55:05 +01:00

46 lines
1.2 KiB
Rust

use crate::{ApiToken, ForgeConfig, ForgeName, ForgeType, Hostname, User};
/// The derived information about a Forge, used to create interactions with it
#[derive(Clone, Debug, derive_more::Constructor)]
pub struct ForgeDetails {
forge_name: ForgeName,
forge_type: ForgeType,
hostname: Hostname,
user: User,
token: ApiToken,
// API Token
// Private SSH Key Path
}
impl ForgeDetails {
pub const fn forge_name(&self) -> &ForgeName {
&self.forge_name
}
pub const fn forge_type(&self) -> ForgeType {
self.forge_type
}
pub const fn hostname(&self) -> &Hostname {
&self.hostname
}
pub const fn user(&self) -> &User {
&self.user
}
pub const fn token(&self) -> &ApiToken {
&self.token
}
pub fn with_hostname(self, hostname: Hostname) -> Self {
let mut me = self;
me.hostname = hostname;
me
}
}
impl From<(&ForgeName, &ForgeConfig)> for ForgeDetails {
fn from(forge: (&ForgeName, &ForgeConfig)) -> Self {
Self {
forge_name: forge.0.clone(),
forge_type: forge.1.forge_type(),
hostname: forge.1.hostname(),
user: forge.1.user(),
token: forge.1.token(),
}
}
}