-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathtrack_endpoint.rs
39 lines (35 loc) · 1.15 KB
/
track_endpoint.rs
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
use derivative::Derivative;
use editoast_common::Identifier;
use serde::Deserialize;
use serde::Serialize;
use super::Direction;
use super::Endpoint;
#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq, Eq, Hash)]
#[derivative(Default)]
#[serde(deny_unknown_fields)]
pub struct TrackEndpoint {
#[derivative(Default(value = "Endpoint::Begin"))]
pub endpoint: Endpoint,
#[derivative(Default(value = r#""InvalidRef".into()"#))]
pub track: Identifier,
}
impl TrackEndpoint {
/// Create a new `TrackEndpoint` from a track id and an endpoint.
pub fn new<T: AsRef<str>>(track: T, endpoint: Endpoint) -> Self {
TrackEndpoint {
track: track.as_ref().into(),
endpoint,
}
}
/// Create a `TrackEndpoint` from a track id and a direction.
pub fn from_track_and_direction<T: AsRef<str>>(track: T, dir: Direction) -> TrackEndpoint {
let endpoint = match dir {
Direction::StartToStop => Endpoint::End,
Direction::StopToStart => Endpoint::Begin,
};
TrackEndpoint {
track: track.as_ref().into(),
endpoint,
}
}
}