mpd/
mount.rs

1//! The module describes data structures for MPD (virtual) mounts system
2//!
3//! This mounts has nothing to do with system-wide Unix mounts, as they are
4//! implemented inside MPD only, so they doesn't require root access.
5//!
6//! The MPD mounts are plugin-based, so MPD can mount any resource as
7//! a source of songs for its database (like network shares).
8//!
9//! Possible, but inactive, mounts are named "neighbors" and can be
10//! listed with `neighbors()` method.
11
12use crate::convert::FromMap;
13use crate::error::{Error, ProtoError};
14
15use std::collections::BTreeMap;
16
17/// Mount point
18#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
19#[derive(Clone, Debug, PartialEq)]
20pub struct Mount {
21    /// mount point name
22    pub name: String,
23    /// mount storage URI
24    pub storage: String,
25}
26
27impl FromMap for Mount {
28    fn from_map(map: BTreeMap<String, String>) -> Result<Mount, Error> {
29        Ok(Mount {
30            name: map.get("mount").map(|s| s.to_owned()).ok_or(Error::Proto(ProtoError::NoField("mount")))?,
31            storage: map.get("storage").map(|s| s.to_owned()).ok_or(Error::Proto(ProtoError::NoField("storage")))?,
32        })
33    }
34}
35
36/// Neighbor
37#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
38#[derive(Clone, Debug, PartialEq)]
39pub struct Neighbor {
40    /// neighbor name
41    pub name: String,
42    /// neighbor storage URI
43    pub storage: String,
44}
45
46impl FromMap for Neighbor {
47    fn from_map(map: BTreeMap<String, String>) -> Result<Neighbor, Error> {
48        Ok(Neighbor {
49            name: map.get("name").map(|s| s.to_owned()).ok_or(Error::Proto(ProtoError::NoField("name")))?,
50            storage: map.get("neighbor").map(|s| s.to_owned()).ok_or(Error::Proto(ProtoError::NoField("neighbor")))?,
51        })
52    }
53}