Remove .unwrap() from examples, they are bad practice
This commit is contained in:
parent
244a34057f
commit
939541599f
47
src/lib.rs
47
src/lib.rs
|
@ -325,10 +325,13 @@ impl Mpv {
|
||||||
///
|
///
|
||||||
/// #Example
|
/// #Example
|
||||||
/// ```
|
/// ```
|
||||||
/// # use mpvipc::Mpv;
|
/// # use mpvipc::{Mpv, Error};
|
||||||
/// let mpv = Mpv::connect("/tmp/mpvsocket").unwrap();
|
/// # fn main() -> Result<(), Error> {
|
||||||
/// let paused: bool = mpv.get_property("pause").unwrap();
|
/// let mpv = Mpv::connect("/tmp/mpvsocket")?;
|
||||||
/// let title: String = mpv.get_property("media-title").unwrap();
|
/// let paused: bool = mpv.get_property("pause")?;
|
||||||
|
/// let title: String = mpv.get_property("media-title")?;
|
||||||
|
/// # Ok(())
|
||||||
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn get_property<T: GetPropertyTypeHandler>(&self, property: &str) -> Result<T, Error> {
|
pub fn get_property<T: GetPropertyTypeHandler>(&self, property: &str) -> Result<T, Error> {
|
||||||
T::get_property_generic(self, property)
|
T::get_property_generic(self, property)
|
||||||
|
@ -346,9 +349,12 @@ impl Mpv {
|
||||||
/// #Example
|
/// #Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use mpvipc::Mpv;
|
/// # use mpvipc::{Mpv, Error};
|
||||||
/// let mpv = Mpv::connect("/tmp/mpvsocket").unwrap();
|
/// # fn main() -> Result<(), Error> {
|
||||||
/// let title = mpv.get_property_string("media-title").unwrap();
|
/// let mpv = Mpv::connect("/tmp/mpvsocket")?;
|
||||||
|
/// let title = mpv.get_property_string("media-title")?;
|
||||||
|
/// # Ok(())
|
||||||
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn get_property_string(&self, property: &str) -> Result<String, Error> {
|
pub fn get_property_string(&self, property: &str) -> Result<String, Error> {
|
||||||
get_mpv_property_string(self, property)
|
get_mpv_property_string(self, property)
|
||||||
|
@ -364,11 +370,10 @@ impl Mpv {
|
||||||
///
|
///
|
||||||
/// #Example
|
/// #Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```ignore
|
||||||
/// # use mpvipc::Mpv;
|
/// let mut mpv = Mpv::connect("/tmp/mpvsocket")?;
|
||||||
/// let mut mpv = Mpv::connect("/tmp/mpvsocket").unwrap();
|
|
||||||
/// loop {
|
/// loop {
|
||||||
/// let event = mpv.event_listen().unwrap();
|
/// let event = mpv.event_listen()?;
|
||||||
/// println!("{:?}", event);
|
/// println!("{:?}", event);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -411,14 +416,17 @@ impl Mpv {
|
||||||
///
|
///
|
||||||
/// #Example
|
/// #Example
|
||||||
/// ```
|
/// ```
|
||||||
/// # use mpvipc::Mpv;
|
/// # use mpvipc::{Mpv, Error};
|
||||||
/// let mpv = Mpv::connect("/tmp/mpvsocket").unwrap();
|
/// # fn main() -> Result<(), Error> {
|
||||||
|
/// let mpv = Mpv::connect("/tmp/mpvsocket")?;
|
||||||
///
|
///
|
||||||
/// //Run command 'playlist-shuffle' which takes no arguments
|
/// //Run command 'playlist-shuffle' which takes no arguments
|
||||||
/// mpv.run_command("playlist-shuffle", &[]);
|
/// mpv.run_command("playlist-shuffle", &[])?;
|
||||||
///
|
///
|
||||||
/// //Run command 'seek' which in this case takes two arguments
|
/// //Run command 'seek' which in this case takes two arguments
|
||||||
/// mpv.run_command("seek", &["0", "absolute"]);
|
/// mpv.run_command("seek", &["0", "absolute"])?;
|
||||||
|
/// # Ok(())
|
||||||
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn run_command(&self, command: &str, args: &[&str]) -> Result<(), Error> {
|
pub fn run_command(&self, command: &str, args: &[&str]) -> Result<(), Error> {
|
||||||
run_mpv_command(self, command, args)
|
run_mpv_command(self, command, args)
|
||||||
|
@ -592,9 +600,12 @@ impl Mpv {
|
||||||
///
|
///
|
||||||
/// #Example
|
/// #Example
|
||||||
/// ```
|
/// ```
|
||||||
/// # use mpvipc::Mpv;
|
/// # use mpvipc::{Mpv, Error};
|
||||||
/// let mpv = Mpv::connect("/tmp/mpvsocket").unwrap();
|
/// # fn main() -> Result<(), Error> {
|
||||||
/// mpv.set_property("pause", true);
|
/// let mpv = Mpv::connect("/tmp/mpvsocket")?;
|
||||||
|
/// mpv.set_property("pause", true)?;
|
||||||
|
/// # Ok(())
|
||||||
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn set_property<T: SetPropertyTypeHandler<T>>(
|
pub fn set_property<T: SetPropertyTypeHandler<T>>(
|
||||||
&self,
|
&self,
|
||||||
|
|
Loading…
Reference in New Issue