libmpv_client/types/
mod.rs

1//! Definitions and trait implementations for the various types that can be used to communicate with mpv.
2pub(crate) mod basics;
3pub(crate) mod node;
4pub(crate) mod node_array;
5pub(crate) mod node_map;
6pub(crate) mod byte_array;
7pub(crate) mod traits;
8mod tests;
9
10pub use node::Node;
11pub use node_array::NodeArray;
12pub use node_map::NodeMap;
13pub use byte_array::ByteArray;
14pub use basics::OsdString;
15
16pub use traits::MpvFormat;
17pub use traits::MpvSend;
18pub use traits::MpvRecv;
19
20use libmpv_client_sys::mpv_format;
21
22/// A type representing the possible data types used in communication with mpv.
23pub struct Format(pub(crate) mpv_format);
24
25impl Format {
26    /// A [`Format`] representing [`MPV_FORMAT_NONE`](libmpv_client_sys::mpv_format_MPV_FORMAT_NONE),
27    /// sometimes returned from mpv to denote an error or other special circumstance.
28    pub const NONE: Format = Format(libmpv_client_sys::mpv_format_MPV_FORMAT_NONE);
29    /// A [`Format`] representing Rust's [`String`]
30    /// and mpv's [`MPV_FORMAT_STRING`](libmpv_client_sys::mpv_format_MPV_FORMAT_STRING).
31    ///
32    /// It represents a raw property string, like using `${=property}` in `input.conf`.
33    /// See [the mpv docs on raw and formatted properties](https://mpv.io/manual/stable/#raw-and-formatted-properties).
34    ///
35    /// <div class="warning">
36    ///
37    /// # Warning
38    /// Although the encoding is usually UTF-8, this is not always the case. File tags often store strings in some legacy codepage,
39    /// and even filenames don't necessarily have to be in UTF-8 (at least on Linux).
40    /// 
41    /// If this crate receives invalid UTF-8, a [`RustError::InvalidUtf8`](crate::error::RustError::InvalidUtf8) may be returned.
42    ///
43    /// On Windows, filenames are always UTF-8, and libmpv converts between UTF-8 and UTF-16 when using Win32 API functions.
44    ///
45    /// </div>
46    pub const STRING: Format = Format(libmpv_client_sys::mpv_format_MPV_FORMAT_STRING);
47    /// A [`Format`] representing [`OsdString`] (a New Type around [`String`])
48    /// and mpv's [`MPV_FORMAT_OSD_STRING`](libmpv_client_sys::mpv_format_MPV_FORMAT_OSD_STRING).
49    ///
50    /// It represents an OSD property string, like using `${property}` in `input.conf`.
51    /// See [the mpv docs on raw and formatted properties](https://mpv.io/manual/stable/#raw-and-formatted-properties).
52    ///
53    /// In many cases, this is the same as the raw string, but in other cases it's formatted for display on OSD.
54    ///
55    /// It's intended to be human-readable. Do not attempt to parse these strings.
56    pub const OSD_STRING: Format = Format(libmpv_client_sys::mpv_format_MPV_FORMAT_OSD_STRING);
57    /// A [`Format`] representing Rust's [`bool`]
58    /// and mpv's [`MPV_FORMAT_FLAG`](libmpv_client_sys::mpv_format_MPV_FORMAT_FLAG).
59    pub const FLAG: Format = Format(libmpv_client_sys::mpv_format_MPV_FORMAT_FLAG);
60    /// A [`Format`] representing Rust's [`i64`]
61    /// and mpv's [`MPV_FORMAT_INT64`](libmpv_client_sys::mpv_format_MPV_FORMAT_INT64).
62    pub const INT64: Format = Format(libmpv_client_sys::mpv_format_MPV_FORMAT_INT64);
63    /// A [`Format`] representing Rust's [`f64`]
64    /// and mpv's [`MPV_FORMAT_DOUBLE`](libmpv_client_sys::mpv_format_MPV_FORMAT_DOUBLE).
65    pub const DOUBLE: Format = Format(libmpv_client_sys::mpv_format_MPV_FORMAT_DOUBLE);
66    /// A [`Format`] representing the crate's [`Node`]
67    /// and mpv's [`MPV_FORMAT_NODE`](libmpv_client_sys::mpv_format_MPV_FORMAT_NODE).
68    pub const NODE: Format = Format(libmpv_client_sys::mpv_format_MPV_FORMAT_NODE);
69    /// A [`Format`] representing the crate's [`NodeArray`] (a type alias for [`Vec<Node>`])
70    /// and mpv's [`MPV_FORMAT_NODE_ARRAY`](libmpv_client_sys::mpv_format_MPV_FORMAT_NODE_ARRAY).
71    pub const NODE_ARRAY: Format = Format(libmpv_client_sys::mpv_format_MPV_FORMAT_NODE_ARRAY);
72    /// A [`Format`] representing the crate's [`NodeMap`] (a type alias for [`HashMap<String, Node>`](std::collections::HashMap))
73    /// and mpv's [`MPV_FORMAT_NODE_MAP`](libmpv_client_sys::mpv_format_MPV_FORMAT_NODE_MAP).
74    pub const NODE_MAP: Format = Format(libmpv_client_sys::mpv_format_MPV_FORMAT_NODE_MAP);
75    /// A [`Format`] representing the crate's [`ByteArray`] (a type alias for [`Vec<u8>`])
76    /// and mpv's [`MPV_FORMAT_BYTE_ARRAY`](libmpv_client_sys::mpv_format_MPV_FORMAT_BYTE_ARRAY).
77    pub const BYTE_ARRAY: Format = Format(libmpv_client_sys::mpv_format_MPV_FORMAT_BYTE_ARRAY);
78}