@@ -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" ) ]
2725use serde:: { Deserialize , Serialize } ;
26+ #[ cfg( feature = "std" ) ]
27+ use std:: { ffi:: OsStr , net:: ToSocketAddrs , path:: Path } ;
2828
2929/// Threadsafe shared storage for string.
3030pub 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
11361136impl < 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
12001200impl < 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