Skip to content

Commit

Permalink
1. Raising Library Version
Browse files Browse the repository at this point in the history
2. Correcting minor errors
3. Added compatibility with 'StdErr (or std:: error:: Error)' (verification required)
4. Added minor additional features to 'FlockError'
5. Default Debug for 'FlockError' has been modified to add compatibility with 'StdErr'
  • Loading branch information
denisandroid committed Dec 26, 2021
1 parent 36b7d6d commit 613f86b
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ Cargo.lock
**/*.rs.bk

test_file
async_file
async_file
file
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cluFlock"
version = "1.2.6"
version = "1.2.7"
authors = ["Denis Kotlyarov (Денис Котляров) <[email protected]>"]
repository = "https://github.com/clucompany/cluFlock.git"
license = " Apache-2.0"
Expand Down
75 changes: 73 additions & 2 deletions src/data/err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,65 @@
//! Error structures used in cluFlock methods.
//!
use core::fmt::Debug;
use core::fmt::Display;
use std::error::Error;
use crate::element::FlockElement;
use core::ops::Deref;

/// The standard error for Flock methods, from the error you can get a borrowed value.
#[derive(Debug)]
//#[derive(Debug)]
pub struct FlockError<T> where T: FlockElement {
data: T,
err: std::io::Error,
}

impl<T> Error for FlockError<T> where T: FlockElement {
#[inline(always)]
fn source(&self) -> Option<&(dyn Error + 'static)> {
Error::source(&self.err)
}

/*#[inline(always)] <<-- TODO, UNSTABLE unstable(feature = "backtrace", issue = "53487")
fn backtrace(&self) -> Option<&Backtrace> {
Error::backtrace(&self.err)
}*/

/*#[inline(always)] <<-- TODO, UNSTABLE issue = "60784"
fn type_id(&self, _: private::Internal) -> TypeId {
}
*/

#[allow(deprecated)]
#[inline(always)]
fn description(&self) -> &str {
Error::description(&self.err)
}

#[allow(deprecated)]
#[inline(always)]
fn cause(&self) -> Option<&dyn Error> {
Error::cause(&self.err)
}
}

// Required only for compatibility with StdErr(Error).
impl<T> Display for FlockError<T> where T: FlockElement {
#[inline(always)]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
Display::fmt(&self.err, f)
}
}

// Required only for compatibility with StdErr(Error).
impl<T> Debug for FlockError<T> where T: FlockElement {
#[inline(always)]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
Debug::fmt(&self.err, f)
}
}

impl<T> From<(T, std::io::Error)> for FlockError<T> where T: FlockElement {
#[inline(always)]
fn from((data, err): (T, std::io::Error)) -> Self {
Expand All @@ -28,12 +77,34 @@ impl<T> FlockError<T> where T: FlockElement {
}
}

#[inline(always)]
pub fn get_debug_data(&self) -> &impl Debug where T: Debug {
&self.data
}

#[inline(always)]
pub fn get_debug_err(&self) -> &impl Debug {
&self.err
}

/// Retrieve only the data from the error structure.
#[inline(always)]
pub fn into(self) -> T {
self.into_data()
}

/// Get a link to data.
#[inline(always)]
pub fn as_data(&self) -> &T {
&self.data
}

/// Get a link to err.
#[inline(always)]
pub fn as_err(&self) -> &std::io::Error {
&self.err
}

/// Retrieve only the data from the error structure.
#[inline(always)]
pub fn into_data(self) -> T {
Expand Down Expand Up @@ -79,6 +150,6 @@ impl<T> Deref for FlockError<T> where T: FlockElement {

#[inline(always)]
fn deref(&self) -> &Self::Target {
&self.err
self.as_err()
}
}
2 changes: 1 addition & 1 deletion src/data/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<T> Debug for FlockLock<T> where T: Debug + FlockElement + WaitFlockUnlock {
impl<T> FlockLock<T> where T: FlockElement + WaitFlockUnlock {
/// Create lock surveillance structure, unsafe because it
/// is not known if a lock has been created before.
#[deprecated]
#[deprecated(since="1.2.6", note="please use `force_new` instead")]
#[inline]
pub unsafe fn new(t: T) -> Self {
Self::force_new(t)
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ mod os_release {

#[cfg(windows)]
pub mod windows;

pub mod r#dyn;
}

#[doc(hidden)]
Expand Down

0 comments on commit 613f86b

Please sign in to comment.