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
// This is not a normal Rust module! It's included directly into v2.rs,
// possibly after build-time preprocessing. See v2.rs for an explanation
// of how this works.
/// Specify another service which should be used as the base for this
/// service.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Extends {
/// The name of a service to extend.
pub service: RawOr<String>,
/// The file in which the service to extend is defined. Defaults to
/// the current file.
#[serde(skip_serializing_if = "Option::is_none")]
pub file: Option<RawOr<PathBuf>>,
/// PRIVATE. Mark this struct as having unknown fields for future
/// compatibility. This prevents direct construction and exhaustive
/// matching. This needs to be be public because of
/// http://stackoverflow.com/q/39277157/12089
#[doc(hidden)]
#[serde(default, skip_serializing, skip_deserializing)]
pub _phantom: PhantomData<()>,
}
impl Extends {
/// Create a new `Extends` by specifying the service name.
///
/// ```
/// use docker_compose::v2 as dc;
/// dc::Extends::new("webdefaults");
/// ```
pub fn new<S: Into<String>>(service: S) -> Extends {
Extends {
service: value(service.into()),
file: Default::default(),
_phantom: PhantomData,
}
}
}
#[test]
fn extends_can_be_roundtripped() {
let yaml = r#"---
"file": "bar/docker-compose.yml"
"service": "foo"
"#;
assert_roundtrip!(Extends, yaml);
}