-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.rs
More file actions
65 lines (52 loc) · 2.29 KB
/
Copy pathmod.rs
File metadata and controls
65 lines (52 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! Module defining gist hosts.
//!
//! A host is an external (web) service that hosts gists, and allows users to paste snippets
//! of code to share with others. gist.github.com is a prime example; others are the various
//! "pastebins", including the pastebin.com namesake.
mod github;
use std::collections::HashMap;
use std::io;
use std::sync::Arc;
use super::gist::{self, Gist};
/// Represents a gists' host: a (web) service that hosts gists (code snippets).
/// Examples include gist.github.com.
pub trait Host : Send + Sync {
// Returns a user-visible name of the gists' host.
fn name(&self) -> &str;
/// Fetch a current version of the gist.
///
/// If the gist has been downloaded previously,
/// it may be updated instead (e.g. via pull rather than clone
/// if its a Git repo).
fn fetch_gist(&self, gist: &Gist) -> io::Result<()>;
/// Return a URL to a HTML page that can display the gist.
/// This may involve talking to the remote host.
fn gist_url(&self, gist: &Gist) -> io::Result<String>;
/// Return a structure with information/metadata about the gist.
///
/// Note: The return type for this method is io::Result<Option<Info>>
/// rather than Option<io::Result<Info>> because the availability of
/// gist metadata may be gist-specific (i.e. some gists have it,
/// some don't).
fn gist_info(&self, _: &Gist) -> io::Result<Option<gist::Info>> {
// This default indicates the host doesn't expose any gist metadata.
Ok(None)
}
/// Return a (fetched) gist corresponding to the given URL.
/// The URL will typically point to a user-facing HTML page of the gist.
///
/// Note: The return type of this method is an Option (Option<io::Result<Gist>>)
/// because the URL may not be recognized as belonging to this host.
fn resolve_url(&self, _: &str) -> Option<io::Result<Gist>> {
// This default indicates that the URL wasn't recognized
// as pointing to any gist hosted by this host.
None
}
}
lazy_static! {
/// Mapping of gist host identifiers (like "gh") to Host structs.
pub static ref HOSTS: HashMap<&'static str, Arc<Host>> = hashmap!{
github::ID => Arc::new(github::GitHub::new()) as Arc<Host>,
};
}
pub const DEFAULT_HOST_ID: &'static str = github::ID;