build_script/
cargo_rustc_link_lib.rs

1//! A wrapper for [`cargo_rustc_link_lib`](crate::BuildScript::cargo_rustc_link_lib).
2/// A kind for [`cargo_rustc_link_lib`](crate::BuildScript::cargo_rustc_link_lib).
3#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
4pub enum Kind {
5    /// Known to the compiler as [`dylib`](Self::DYNAMIC_LIBRARY).
6    DynamicLibrary,
7
8    /// Known to the compiler as [`static`](Self::STATIC).
9    Static,
10
11    /// Known to the compiler as [`framework`](Self::FRAMEWORK).
12    Framework,
13}
14
15impl Kind {
16    /// Known to this library as [`DynamicLibrary`](Self::DynamicLibrary).
17    pub const DYNAMIC_LIBRARY: &'static str = "dylib";
18
19    /// Known to this library as [`Static`](Self::Static).
20    pub const STATIC: &'static str = "static";
21
22    /// Known to this library as [`Framework`](Self::Framework).
23    pub const FRAMEWORK: &'static str = "framework";
24}
25
26impl From<Kind> for &'static str {
27    fn from(kind: Kind) -> Self {
28        match kind {
29            Kind::DynamicLibrary => Kind::DYNAMIC_LIBRARY,
30            Kind::Static => Kind::STATIC,
31            Kind::Framework => Kind::FRAMEWORK,
32        }
33    }
34}
35
36impl From<Kind> for String {
37    fn from(kind: Kind) -> Self {
38        let kind: &str = kind.into();
39        kind.into()
40    }
41}
42
43#[cfg(test)]
44mod tests {
45    use super::Kind;
46
47    #[test]
48    fn test_into_string() {
49        let kind: String = Kind::DynamicLibrary.into();
50        assert_eq!(kind, Kind::DYNAMIC_LIBRARY);
51        let kind: String = Kind::Static.into();
52        assert_eq!(kind, Kind::STATIC);
53        let kind: String = Kind::Framework.into();
54        assert_eq!(kind, Kind::FRAMEWORK)
55    }
56}