fixed some method return error types

4-clippy_fmt
Pierre Réveillon 2021-12-01 08:19:21 +01:00
parent 1c9c665a7a
commit 0107178024
4 changed files with 20 additions and 17 deletions

View File

@ -45,6 +45,7 @@ impl MediaPlayerAudioEx for MediaPlayer {
}
}
}
fn get_audio_track_description(&self) -> Option<Vec<TrackDescription>> {
unsafe {
let p0 = sys::libvlc_audio_get_track_description(self.ptr);

View File

@ -53,7 +53,7 @@ impl Instance {
/// Create and initialize a libvlc instance with specified args.
/// Note: args.len() has to be less or equal to i32::MAX
/// Note: libvlc discourages using arguments as these are not guaranteed to be stable between different versions of libvlc
pub fn with_args(args: Option<Vec<String>>) -> Option<Instance> {
pub fn with_args(args: Option<Vec<String>>) -> Result<Instance, InternalError> {
let args_c_ptr: Vec<*const c_char>;
let args_c: Vec<CString>;
if let Some(argv) = args {
@ -74,15 +74,15 @@ impl Instance {
};
if p.is_null() {
return None;
Err(InternalError)
} else {
Ok(Instance { ptr: p })
}
Some(Instance { ptr: p })
}
}
/// Create and initialize a libvlc instance.
pub fn new() -> Option<Instance> {
pub fn new() -> Result<Instance, InternalError> {
Instance::with_args(None)
}
@ -125,25 +125,25 @@ impl Instance {
}
/// Returns a list of audio filters that are available.
pub fn audio_filter_list_get(&self) -> Option<ModuleDescriptionList> {
pub fn audio_filter_list_get(&self) -> Result<ModuleDescriptionList, InternalError> {
unsafe {
let p = sys::libvlc_audio_filter_list_get(self.ptr);
if p.is_null() {
None
Err(InternalError)
} else {
Some(ModuleDescriptionList { ptr: p })
Ok(ModuleDescriptionList { ptr: p })
}
}
}
/// Returns a list of video filters that are available.
pub fn video_filter_list_get(&self) -> Option<ModuleDescriptionList> {
pub fn video_filter_list_get(&self) -> Result<ModuleDescriptionList, InternalError> {
unsafe {
let p = sys::libvlc_video_filter_list_get(self.ptr);
if p.is_null() {
None
Err(InternalError)
} else {
Some(ModuleDescriptionList { ptr: p })
Ok(ModuleDescriptionList { ptr: p })
}
}
}

View File

@ -3,6 +3,7 @@
// Licensed under the MIT license, see the LICENSE file.
use crate::{Instance, InternalError, MediaList};
use std::fmt;
use vlc_sys as sys;
pub struct MediaLibrary {
@ -11,13 +12,13 @@ pub struct MediaLibrary {
impl MediaLibrary {
/// Create an new Media Library object.
pub fn new(instance: &Instance) -> Option<MediaLibrary> {
pub fn new(instance: &Instance) -> Result<MediaLibrary, InternalError> {
unsafe {
let p = sys::libvlc_media_library_new(instance.ptr);
if p.is_null() {
None
Err(InternalError)
} else {
Some(MediaLibrary { ptr: p })
Ok(MediaLibrary { ptr: p })
}
}
}

View File

@ -11,13 +11,13 @@ pub struct MediaList {
impl MediaList {
/// Create an empty media list.
pub fn new(instance: &Instance) -> Option<MediaList> {
pub fn new(instance: &Instance) -> Result<MediaList, InternalError> {
unsafe {
let p = sys::libvlc_media_list_new(instance.ptr);
if p.is_null() {
None
Err(InternalError)
} else {
Some(MediaList { ptr: p })
Ok(MediaList { ptr: p })
}
}
}
@ -45,6 +45,7 @@ impl MediaList {
/// Add media instance to media list.
/// The MediaList::lock should be held upon entering this function.
// TODO: use specific error type since documentation says "-1 if the media list is read-only"
pub fn add_media(&self, md: &Media) -> Result<(), InternalError> {
unsafe {
if sys::libvlc_media_list_add_media(self.ptr, md.ptr) == 0 {