fix some clippy::wrong_self_convention
This commit is contained in:
@@ -95,7 +95,7 @@ impl<'a> TCString<'a> {
|
|||||||
/// Convert the TCString, in place, into one of the C variants. If this is not
|
/// Convert the TCString, in place, into one of the C variants. If this is not
|
||||||
/// possible, such as if the string contains an embedded NUL, then the string
|
/// possible, such as if the string contains an embedded NUL, then the string
|
||||||
/// remains unchanged.
|
/// remains unchanged.
|
||||||
fn to_c_string(&mut self) {
|
fn to_c_string_mut(&mut self) {
|
||||||
if matches!(self, TCString::String(_)) {
|
if matches!(self, TCString::String(_)) {
|
||||||
// we must take ownership of the String in order to try converting it,
|
// we must take ownership of the String in order to try converting it,
|
||||||
// leaving the underlying TCString as its default (None)
|
// leaving the underlying TCString as its default (None)
|
||||||
@@ -267,11 +267,11 @@ pub unsafe extern "C" fn tc_string_content(tcstring: *mut TCString) -> *const li
|
|||||||
|
|
||||||
// if we have a String, we need to consume it and turn it into
|
// if we have a String, we need to consume it and turn it into
|
||||||
// a CString.
|
// a CString.
|
||||||
tcstring.to_c_string();
|
tcstring.to_c_string_mut();
|
||||||
|
|
||||||
match tcstring {
|
match tcstring {
|
||||||
TCString::CString(cstring) => cstring.as_ptr(),
|
TCString::CString(cstring) => cstring.as_ptr(),
|
||||||
TCString::String(_) => std::ptr::null(), // to_c_string failed
|
TCString::String(_) => std::ptr::null(), // to_c_string_mut failed
|
||||||
TCString::CStr(cstr) => cstr.as_ptr(),
|
TCString::CStr(cstr) => cstr.as_ptr(),
|
||||||
TCString::InvalidUtf8(_, _) => std::ptr::null(),
|
TCString::InvalidUtf8(_, _) => std::ptr::null(),
|
||||||
TCString::None => unreachable!(),
|
TCString::None => unreachable!(),
|
||||||
@@ -427,37 +427,37 @@ mod test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cstring_to_c_string() {
|
fn cstring_to_c_string_mut() {
|
||||||
let mut tcstring = make_cstring();
|
let mut tcstring = make_cstring();
|
||||||
tcstring.to_c_string();
|
tcstring.to_c_string_mut();
|
||||||
assert_eq!(tcstring, make_cstring()); // unchanged
|
assert_eq!(tcstring, make_cstring()); // unchanged
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cstr_to_c_string() {
|
fn cstr_to_c_string_mut() {
|
||||||
let mut tcstring = make_cstr();
|
let mut tcstring = make_cstr();
|
||||||
tcstring.to_c_string();
|
tcstring.to_c_string_mut();
|
||||||
assert_eq!(tcstring, make_cstr()); // unchanged
|
assert_eq!(tcstring, make_cstr()); // unchanged
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn string_to_c_string() {
|
fn string_to_c_string_mut() {
|
||||||
let mut tcstring = make_string();
|
let mut tcstring = make_string();
|
||||||
tcstring.to_c_string();
|
tcstring.to_c_string_mut();
|
||||||
assert_eq!(tcstring, make_cstring()); // converted to CString, same content
|
assert_eq!(tcstring, make_cstring()); // converted to CString, same content
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn string_with_nul_to_c_string() {
|
fn string_with_nul_to_c_string_mut() {
|
||||||
let mut tcstring = make_string_with_nul();
|
let mut tcstring = make_string_with_nul();
|
||||||
tcstring.to_c_string();
|
tcstring.to_c_string_mut();
|
||||||
assert_eq!(tcstring, make_string_with_nul()); // unchanged
|
assert_eq!(tcstring, make_string_with_nul()); // unchanged
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn invalid_to_c_string() {
|
fn invalid_to_c_string_mut() {
|
||||||
let mut tcstring = make_invalid();
|
let mut tcstring = make_invalid();
|
||||||
tcstring.to_c_string();
|
tcstring.to_c_string_mut();
|
||||||
assert_eq!(tcstring, make_invalid()); // unchanged
|
assert_eq!(tcstring, make_invalid()); // unchanged
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ impl TCTask {
|
|||||||
|
|
||||||
/// Make an mutable TCTask into a immutable TCTask. Does nothing if the task
|
/// Make an mutable TCTask into a immutable TCTask. Does nothing if the task
|
||||||
/// is already immutable.
|
/// is already immutable.
|
||||||
|
#[allow(clippy::wrong_self_convention)] // to_immut_mut is not better!
|
||||||
fn to_immut(&mut self) {
|
fn to_immut(&mut self) {
|
||||||
self.inner = match std::mem::replace(&mut self.inner, Inner::Invalid) {
|
self.inner = match std::mem::replace(&mut self.inner, Inner::Invalid) {
|
||||||
Inner::Immutable(task) => Inner::Immutable(task),
|
Inner::Immutable(task) => Inner::Immutable(task),
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ pub(crate) trait PassByValue: Sized {
|
|||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// `self` must be a valid CType.
|
/// `self` must be a valid CType.
|
||||||
|
#[allow(clippy::wrong_self_convention)]
|
||||||
unsafe fn from_ctype(self) -> Self::RustType;
|
unsafe fn from_ctype(self) -> Self::RustType;
|
||||||
|
|
||||||
/// Convert a Rust value to a C value.
|
/// Convert a Rust value to a C value.
|
||||||
|
|||||||
Reference in New Issue
Block a user