Skip to main content

specfold_core/workspace/visibility/
forge.rs

1//! The hosting service asked for each submodule's visibility, behind a trait so tests answer
2//! without a network.
3
4use std::fmt;
5
6/// Why the forge gave no visibility.
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub enum ForgeError {
9    /// The URL names no repository on this forge.
10    Unsupported(String),
11    /// The forge cannot be reached: no network, no client, or not signed in.
12    Unreachable(String),
13    /// The forge answered but not with a visibility (no such repository, no access).
14    Failed(String),
15}
16
17impl fmt::Display for ForgeError {
18    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19        match self {
20            ForgeError::Unsupported(m) | ForgeError::Unreachable(m) | ForgeError::Failed(m) => f.write_str(m),
21        }
22    }
23}
24
25/// A hosting service that knows whether a repository is public.
26pub trait Forge {
27    /// The service's name, for messages.
28    fn name(&self) -> &str;
29    /// The repository a clone URL names on this forge, or Unsupported.
30    fn repository(&self, url: &str) -> Result<String, ForgeError>;
31    /// The visibility of a repository `repository` returned, as the forge spells it.
32    fn visibility(&self, repository: &str) -> Result<String, ForgeError>;
33}