Skip to content

Commit 7be5b09

Browse files
committed
refactor: Changes done by cargo fmt
1 parent 1d156c8 commit 7be5b09

File tree

3 files changed

+18
-25
lines changed

3 files changed

+18
-25
lines changed

src/c.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44
55
#![cfg(all(feature = "std", feature = "c-types"))]
66

7-
use std::os::raw::c_char;
87
use std::ffi::CStr;
8+
use std::os::raw::c_char;
99
use std::str::Utf8Error;
1010

1111
#[cfg(any(feature = "panic-if-null", debug_assertions))]
1212
use super::panic_if_null;
1313

1414
/// Convert a reference to a C string into a static reference to Rust `str`.
15-
///
15+
///
1616
/// # Safety
17-
///
17+
///
1818
/// The pointer must be a valid reference or behavior is undefined.
19-
///
19+
///
2020
/// # Errors
21-
///
21+
///
2222
/// If the C string is not a valid UTF-8 string.
2323
#[must_use]
2424
#[inline]

src/lib.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! # FFI opaque pointers.
2-
//!
2+
//!
33
//! FFI to use Rust objects from C as opaque pointer.
44
55
#![allow(unsafe_code)]
@@ -8,9 +8,7 @@
88
#![deny(clippy::complexity)]
99
#![deny(clippy::cognitive_complexity)]
1010
#![allow(clippy::needless_return)] // To avoid surprise in devs more familiar where return is always explicit
11-
1211
#![doc(html_no_source)]
13-
1412
#![no_std]
1513

1614
#[cfg(all(feature = "alloc", not(feature = "std")))]
@@ -36,18 +34,15 @@ fn panic_if_null<T>(pointer: *const T) {
3634
}
3735

3836
/// Get a heap-allocated raw pointer without ownership.
39-
///
37+
///
4038
/// To back to manage the memory with ownership use [`own_back<T>()`].
4139
#[cfg(any(feature = "alloc", feature = "std"))]
4240
#[inline]
4341
pub fn raw<T>(data: T) -> *mut T {
4442
return Box::into_raw(Box::new(data));
4543
}
4644

47-
#[deprecated(
48-
since = "0.7.2",
49-
note = "Use `own_back<T>()` instead"
50-
)]
45+
#[deprecated(since = "0.7.2", note = "Use `own_back<T>()` instead")]
5146
#[allow(missing_docs)]
5247
#[cfg(any(feature = "alloc", feature = "std"))]
5348
#[inline]
@@ -56,11 +51,11 @@ pub unsafe fn free<T>(pointer: *mut T) {
5651
}
5752

5853
/// Opposite of [`raw<T>()`], to use Rust's ownership as usually.
59-
///
54+
///
6055
/// # Safety
61-
///
56+
///
6257
/// The pointer must be a valid reference and never call it twice or behavior is undefined.
63-
///
58+
///
6459
/// That could produce a HEAP error that produce a crash.
6560
#[doc(alias = "free")]
6661
#[cfg(any(feature = "alloc", feature = "std"))]
@@ -74,12 +69,12 @@ pub unsafe fn own_back<T>(pointer: *mut T) -> T {
7469
}
7570

7671
/// Reference to a object but without back to own it.
77-
///
72+
///
7873
/// That's the difference with [`own_back<T>()`], you must
7974
/// use [`own_back<T>()`] to own it again and it will be dropped.
80-
///
75+
///
8176
/// # Safety
82-
///
77+
///
8378
/// Invalid pointer or call it twice could cause an undefined behavior or heap error and a crash.
8479
#[inline]
8580
pub unsafe fn object<'a, T>(pointer: *const T) -> &'a T {
@@ -90,12 +85,12 @@ pub unsafe fn object<'a, T>(pointer: *const T) -> &'a T {
9085
}
9186

9287
/// Mutable reference to a object but without back to own it.
93-
///
88+
///
9489
/// That's the difference with [`own_back<T>()`], you must
9590
/// use [`own_back<T>()`] to own it again and it will be dropped.
96-
///
91+
///
9792
/// # Safety
98-
///
93+
///
9994
/// Invalid pointer or call it twice could cause an undefined behavior or heap error and a crash.
10095
#[inline]
10196
pub unsafe fn mut_object<'a, T>(pointer: *mut T) -> &'a mut T {

tests/pointer.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ struct TestIt {
66

77
impl TestIt {
88
pub fn new(value: u8) -> Self {
9-
Self {
10-
value,
11-
}
9+
Self { value }
1210
}
1311
pub fn add(&mut self, value: u8) {
1412
self.value += value;

0 commit comments

Comments
 (0)