Skip to content

Commit 28ef678

Browse files
committed
fixed minor warnings
1 parent 83a18de commit 28ef678

File tree

5 files changed

+32
-31
lines changed

5 files changed

+32
-31
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "imstr"
3-
version = "0.2.0"
4-
edition = "2021"
3+
version = "0.3.0"
4+
edition = "2024"
55
description = "Cheaply clonable and slicable immutable strings"
66
documentation = "https://docs.rs/imstr"
77
repository = "https://github.com/xfbs/imstr"

src/data.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ impl<T> Data<T> for Arc<T> {
115115
}
116116

117117
fn get(&self) -> &T {
118-
&self
118+
self
119119
}
120120

121121
fn get_mut(&mut self) -> Option<&mut T> {
122122
Arc::get_mut(self)
123123
}
124124

125125
fn ptr_eq(&self, other: &Self) -> bool {
126-
Arc::ptr_eq(&self, &other)
126+
Arc::ptr_eq(self, other)
127127
}
128128
}
129129

@@ -133,15 +133,15 @@ impl<T> Data<T> for Rc<T> {
133133
}
134134

135135
fn get(&self) -> &T {
136-
&self
136+
self
137137
}
138138

139139
fn get_mut(&mut self) -> Option<&mut T> {
140140
Rc::get_mut(self)
141141
}
142142

143143
fn ptr_eq(&self, other: &Self) -> bool {
144-
Rc::ptr_eq(&self, &other)
144+
Rc::ptr_eq(self, other)
145145
}
146146
}
147147

@@ -151,15 +151,15 @@ impl<T: Clone> Data<T> for Box<T> {
151151
}
152152

153153
fn get(&self) -> &T {
154-
&self
154+
self
155155
}
156156

157157
fn get_mut(&mut self) -> Option<&mut T> {
158158
Some(self)
159159
}
160160

161161
fn ptr_eq(&self, other: &Self) -> bool {
162-
core::ptr::eq(&self, &other)
162+
core::ptr::eq(self, other)
163163
}
164164
}
165165

src/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Error types
22
use alloc::fmt::{Display, Formatter, Result};
3-
pub use alloc::string::{FromUtf16Error, FromUtf8Error};
3+
pub use alloc::string::{FromUtf8Error, FromUtf16Error};
44

55
/// A possible error when slicing a [`ImString`](crate::ImString).
66
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -46,8 +46,8 @@ fn slice_error_traits() {
4646
// implements partial eq
4747
assert_eq!(error, new);
4848
// implements debug
49-
alloc::format!("{error:?}");
49+
let _ = alloc::format!("{error:?}");
5050
// implements display
51-
alloc::format!("{new}");
51+
let _ = alloc::format!("{new}");
5252
}
5353
}

src/nom.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ use crate::string::{CharIndices, Chars, ImString};
33
use alloc::string::String;
44
use core::str::FromStr;
55
use nom::{
6-
error::ErrorKind, AsBytes, Compare, CompareResult, Err, ExtendInto, FindSubstring, Input,
7-
Needed, Offset, ParseTo,
6+
AsBytes, Compare, CompareResult, ExtendInto, FindSubstring, Input, Needed, Offset, ParseTo,
87
};
8+
#[cfg(test)]
9+
use nom::{Err, error::ErrorKind};
910

1011
/// Test that the specified function behaves the same regardless of whether the type is `&str` or
1112
/// `ImString`.

src/string.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ use core::{
2121
},
2222
str::FromStr,
2323
};
24-
#[cfg(feature = "std")]
25-
use std::{ffi::OsStr, net::ToSocketAddrs, path::Path};
2624
#[cfg(feature = "serde")]
2725
use serde::{Deserialize, Serialize};
26+
#[cfg(feature = "std")]
27+
use std::{ffi::OsStr, net::ToSocketAddrs, path::Path};
2828

2929
/// Threadsafe shared storage for string.
3030
pub type Threadsafe = Arc<String>;
@@ -136,7 +136,7 @@ impl<S: Data<String>> ImString<S> {
136136
/// ```
137137
pub fn from_std_string(string: String) -> Self {
138138
ImString {
139-
offset: 0..string.as_bytes().len(),
139+
offset: 0..string.len(),
140140
string: S::new(string),
141141
}
142142
}
@@ -183,7 +183,7 @@ impl<S: Data<String>> ImString<S> {
183183
}
184184

185185
let string = self.string.get_mut().unwrap();
186-
return &mut string[self.offset.clone()];
186+
&mut string[self.offset.clone()]
187187
}
188188

189189
unsafe fn try_modify_unchecked<F: FnOnce(&mut String)>(&mut self, f: F) -> bool {
@@ -235,11 +235,11 @@ impl<S: Data<String>> ImString<S> {
235235
/// assert_eq!(string, "hello");
236236
/// ```
237237
pub fn into_std_string(mut self) -> String {
238-
if self.offset.start == 0 {
239-
if let Some(string) = self.string.get_mut() {
240-
string.truncate(self.offset.end);
241-
return core::mem::take(string);
242-
}
238+
if self.offset.start == 0
239+
&& let Some(string) = self.string.get_mut()
240+
{
241+
string.truncate(self.offset.end);
242+
return core::mem::take(string);
243243
}
244244

245245
self.as_str().to_string()
@@ -390,7 +390,7 @@ impl<S: Data<String>> ImString<S> {
390390
/// assert_eq!(sparkle_heart, "💖");
391391
/// ```
392392
pub unsafe fn from_utf8_unchecked(vec: Vec<u8>) -> Self {
393-
ImString::from_std_string(String::from_utf8_unchecked(vec))
393+
unsafe { ImString::from_std_string(String::from_utf8_unchecked(vec)) }
394394
}
395395

396396
/// Converts an [`ImString`] into a byte vector.
@@ -414,8 +414,8 @@ impl<S: Data<String>> ImString<S> {
414414

415415
unsafe fn unchecked_append<F: FnOnce(String) -> String>(&mut self, f: F) {
416416
match self.string.get_mut() {
417-
Some(mut string_ref) if self.offset.start == 0 => {
418-
let mut string: String = core::mem::take(&mut string_ref);
417+
Some(string_ref) if self.offset.start == 0 => {
418+
let mut string: String = core::mem::take(string_ref);
419419
string.truncate(self.offset.end);
420420
*string_ref = f(string);
421421
}
@@ -425,7 +425,7 @@ impl<S: Data<String>> ImString<S> {
425425
}
426426
}
427427

428-
self.offset.end = self.string.get().as_bytes().len();
428+
self.offset.end = self.string.get().len();
429429
}
430430

431431
/// Inserts a character into this string at the specified index.
@@ -534,7 +534,7 @@ impl<S: Data<String>> ImString<S> {
534534
/// assert_eq!(string.pop(), None);
535535
/// ```
536536
pub fn pop(&mut self) -> Option<char> {
537-
let last_char = self.as_str().chars().rev().next()?;
537+
let last_char = self.as_str().chars().next_back()?;
538538
self.offset.end -= last_char.len_utf8();
539539
Some(last_char)
540540
}
@@ -1135,7 +1135,7 @@ impl<S: Data<String>> Eq for ImString<S> {}
11351135

11361136
impl<S: Data<String>> PartialOrd<ImString<S>> for ImString<S> {
11371137
fn partial_cmp(&self, other: &ImString<S>) -> Option<Ordering> {
1138-
self.as_str().partial_cmp(other.as_str())
1138+
Some(self.cmp(other))
11391139
}
11401140
}
11411141

@@ -1199,8 +1199,8 @@ impl<S: Data<String>> Index<RangeFrom<usize>> for ImString<S> {
11991199

12001200
impl<S: Data<String>> Index<RangeFull> for ImString<S> {
12011201
type Output = str;
1202-
fn index(&self, index: RangeFull) -> &str {
1203-
&self.as_str()[index]
1202+
fn index(&self, _index: RangeFull) -> &str {
1203+
self.as_str()
12041204
}
12051205
}
12061206

@@ -1601,7 +1601,7 @@ mod tests {
16011601

16021602
// make sure both versions are identical
16031603
assert_eq!(string_uppercase, &*string_slice);
1604-
drop(string_slice);
1604+
let _ = string_slice;
16051605
assert_eq!(string, string_uppercase);
16061606
}
16071607

0 commit comments

Comments
 (0)