use std::fmt;
use std::convert::TryFrom;
use crate::error::Error;
#[derive(Debug, Clone, PartialEq)]
pub struct Appveyor {
pub(crate) repository: String,
pub(crate) branch: Option<String>,
pub(crate) service: Option<AppveyorService>,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum AppveyorService {
Github,
Bitbucket,
Gitlab,
}
impl fmt::Display for AppveyorService {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use crate::types::badges::AppveyorService::*;
write!(f, "{}", match *self {
Github => "github",
Bitbucket => "bitbucket",
Gitlab => "gitlab",
})
}
}
impl From<String> for Appveyor {
fn from(s: String) -> Appveyor {
Appveyor::new(&s)
}
}
impl<'a> From<&'a str> for Appveyor {
fn from(s: &'a str) -> Appveyor {
Appveyor::new(s)
}
}
impl Appveyor {
pub fn new(repository: &str) -> Appveyor {
Appveyor {
repository: repository.to_string(),
branch: None,
service: None,
}
}
pub fn branch(&mut self, branch: &str) -> &mut Self {
self.branch = Some(branch.to_string());
self
}
pub fn service(&mut self, service: AppveyorService) -> &mut Self {
self.service = Some(service);
self
}
pub fn build(&self) -> Self {
self.clone()
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct CircleCi {
pub(crate) repository: String,
pub(crate) branch: Option<String>,
}
impl From<String> for CircleCi {
fn from(s: String) -> CircleCi {
CircleCi::new(&s)
}
}
impl<'a> From<&'a str> for CircleCi {
fn from(s: &'a str) -> CircleCi {
CircleCi::new(s)
}
}
impl CircleCi {
pub fn new(repository: &str) -> CircleCi {
CircleCi {
repository: repository.to_string(),
branch: None,
}
}
pub fn branch(&mut self, branch: &str) -> &mut Self {
self.branch = Some(branch.to_string());
self
}
pub fn build(&self) -> Self {
self.clone()
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Gitlab {
pub(crate) repository: String,
pub(crate) branch: Option<String>,
}
impl From<String> for Gitlab {
fn from(s: String) -> Gitlab {
Gitlab::new(&s)
}
}
impl<'a> From<&'a str> for Gitlab {
fn from(s: &'a str) -> Gitlab {
Gitlab::new(s)
}
}
impl Gitlab {
pub fn new(repository: &str) -> Gitlab {
Gitlab {
repository: repository.to_string(),
branch: None,
}
}
pub fn branch(&mut self, branch: &str) -> &mut Gitlab {
self.branch = Some(branch.to_string());
self
}
pub fn build(&self) -> Gitlab {
self.clone()
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct TravisCi {
pub(crate) repository: String,
pub(crate) branch: Option<String>,
}
impl From<String> for TravisCi {
fn from(s: String) -> TravisCi {
TravisCi::new(&s)
}
}
impl<'a> From<&'a str> for TravisCi {
fn from(s: &'a str) -> TravisCi {
TravisCi::new(s)
}
}
impl TravisCi {
pub fn new(repository: &str) -> TravisCi {
TravisCi {
repository: repository.to_string(),
branch: None,
}
}
pub fn branch(&mut self, branch: &str) -> &mut TravisCi {
self.branch = Some(branch.to_string());
self
}
pub fn build(&self) -> TravisCi {
self.clone()
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Codecov {
pub(crate) repository: String,
pub(crate) branch: Option<String>,
pub(crate) service: Option<CodecovService>,
}
impl From<String> for Codecov {
fn from(s: String) -> Codecov {
Codecov::new(&s)
}
}
impl<'a> From<&'a str> for Codecov {
fn from(s: &'a str) -> Codecov {
Codecov::new(s)
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum CodecovService {
Github,
Bitbucket,
Gitlab,
}
impl fmt::Display for CodecovService {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use crate::types::badges::CodecovService::*;
write!(f, "{}", match *self {
Github => "github",
Bitbucket => "bitbucket",
Gitlab => "gitlab",
})
}
}
impl Codecov {
pub fn new(repository: &str) -> Codecov {
Codecov {
repository: repository.to_string(),
branch: None,
service: None,
}
}
pub fn branch(&mut self, branch: &str) -> &mut Codecov {
self.branch = Some(branch.to_string());
self
}
pub fn service(&mut self, service: CodecovService) -> &mut Codecov {
self.service = Some(service);
self
}
pub fn build(&self) -> Codecov {
self.clone()
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Coveralls {
pub(crate) repository: String,
pub(crate) branch: Option<String>,
pub(crate) service: Option<CoverallsService>,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum CoverallsService {
Github,
Bitbucket,
Gitlab,
}
impl fmt::Display for CoverallsService {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use crate::types::badges::CoverallsService::*;
write!(f, "{}", match *self {
Github => "github",
Bitbucket => "bitbucket",
Gitlab => "gitlab",
})
}
}
impl From<String> for Coveralls {
fn from(s: String) -> Coveralls {
Coveralls::new(&s)
}
}
impl<'a> From<&'a str> for Coveralls {
fn from(s: &'a str) -> Coveralls {
Coveralls::new(s)
}
}
impl Coveralls {
pub fn new(repository: &str) -> Coveralls {
Coveralls {
repository: repository.to_string(),
branch: None,
service: None,
}
}
pub fn branch(&mut self, branch: &str) -> &mut Coveralls {
self.branch = Some(branch.to_string());
self
}
pub fn service(&mut self, service: CoverallsService) -> &mut Coveralls {
self.service = Some(service);
self
}
pub fn build(&self) -> Coveralls {
self.clone()
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Maintenance {
pub(crate) status: MaintenanceStatus,
}
impl Maintenance {
fn new(status: MaintenanceStatus) -> Maintenance {
Maintenance { status: status }
}
}
impl TryFrom<String> for Maintenance {
type Error = Error;
fn try_from(s: String) -> Result<Self, Self::Error> {
Ok(Maintenance::new(MaintenanceStatus::try_from(s)?))
}
}
impl<'a> TryFrom<&'a str> for Maintenance {
type Error = Error;
fn try_from(s: &'a str) -> Result<Self, Self::Error> {
Ok(Maintenance::new(MaintenanceStatus::try_from(s)?))
}
}
impl From<MaintenanceStatus> for Maintenance {
fn from(m: MaintenanceStatus) -> Maintenance {
Maintenance {
status: m,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum MaintenanceStatus {
Actively,
Passively,
AsIs,
None,
Experimental,
LookingForMaintainer,
Deprecated,
}
impl TryFrom<String> for MaintenanceStatus {
type Error = Error;
fn try_from(s: String) -> Result<Self, Self::Error> {
TryFrom::try_from(s.as_str())
}
}
impl<'a> TryFrom<&'a str> for MaintenanceStatus {
type Error = Error;
fn try_from(s: &'a str) -> Result<Self, Self::Error> {
Ok(match s {
"actively-developed" => MaintenanceStatus::Actively,
"passively-maintained" => MaintenanceStatus::Passively,
"as-is" => MaintenanceStatus::AsIs,
"none" => MaintenanceStatus::None,
"experimental" => MaintenanceStatus::Experimental,
"looking-for-maintainer" => MaintenanceStatus::LookingForMaintainer,
"deprecated" => MaintenanceStatus::Deprecated,
_ => return Err("unrecognized maintenance status string".into()),
})
}
}
impl fmt::Display for MaintenanceStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", match *self {
MaintenanceStatus::Actively => "actively-developed",
MaintenanceStatus::Passively => "passively-maintained",
MaintenanceStatus::AsIs => "as-is",
MaintenanceStatus::None => "none",
MaintenanceStatus::Experimental => "experimental",
MaintenanceStatus::LookingForMaintainer => "looking-for-maintainer",
MaintenanceStatus::Deprecated => "deprecated",
})
}
}