@@ -26,13 +26,13 @@ use crate::{
2626/// Wraps a Rust `String` and provides Python-compatible operations.
2727/// `len()` returns the number of Unicode codepoints (characters), matching Python semantics.
2828#[ derive( Debug , Clone , PartialEq , Default , serde:: Serialize , serde:: Deserialize ) ]
29- pub ( crate ) struct Str ( String ) ;
29+ pub ( crate ) struct Str ( Box < str > ) ;
3030
3131impl Str {
3232 /// Creates a new Str from a Rust String.
3333 #[ must_use]
3434 pub fn new ( s : String ) -> Self {
35- Self ( s)
35+ Self ( s. into ( ) )
3636 }
3737
3838 /// Returns a reference to the inner string.
@@ -41,11 +41,6 @@ impl Str {
4141 & self . 0
4242 }
4343
44- /// Returns a mutable reference to the inner string.
45- pub fn as_string_mut ( & mut self ) -> & mut String {
46- & mut self . 0
47- }
48-
4944 /// Creates a string from the `str()` constructor call.
5045 ///
5146 /// - `str()` with no args returns an empty string
@@ -81,19 +76,19 @@ impl Str {
8176
8277impl From < String > for Str {
8378 fn from ( s : String ) -> Self {
84- Self ( s)
79+ Self ( s. into ( ) )
8580 }
8681}
8782
8883impl From < & str > for Str {
8984 fn from ( s : & str ) -> Self {
90- Self ( s. to_string ( ) )
85+ Self ( s. into ( ) )
9186 }
9287}
9388
9489impl From < Str > for String {
9590 fn from ( value : Str ) -> Self {
96- value. 0
91+ value. 0 . into_string ( )
9792 }
9893}
9994
@@ -202,7 +197,7 @@ pub(crate) fn get_str_slice(s: &str, start: usize, stop: usize, step: i64) -> St
202197}
203198
204199impl std:: ops:: Deref for Str {
205- type Target = String ;
200+ type Target = str ;
206201
207202 fn deref ( & self ) -> & Self :: Target {
208203 & self . 0
@@ -270,7 +265,7 @@ impl PyTrait for Str {
270265 }
271266
272267 fn py_str ( & self , _heap : & Heap < impl ResourceTracker > , _interns : & Interns ) -> Cow < ' static , str > {
273- self . 0 . clone ( ) . into ( )
268+ self . 0 . clone ( ) . into_string ( ) . into ( )
274269 }
275270
276271 fn py_add (
@@ -284,35 +279,6 @@ impl PyTrait for Str {
284279 Ok ( Some ( Value :: Ref ( id) ) )
285280 }
286281
287- fn py_iadd (
288- & mut self ,
289- other : Value ,
290- heap : & mut Heap < impl ResourceTracker > ,
291- self_id : Option < HeapId > ,
292- interns : & Interns ,
293- ) -> Result < bool , crate :: resource:: ResourceError > {
294- match & other {
295- Value :: Ref ( other_id) => {
296- if Some ( * other_id) == self_id {
297- let rhs = self . 0 . clone ( ) ;
298- self . 0 . push_str ( & rhs) ;
299- } else if let HeapData :: Str ( rhs) = heap. get ( * other_id) {
300- self . 0 . push_str ( rhs. as_str ( ) ) ;
301- } else {
302- return Ok ( false ) ;
303- }
304- // Drop the other value - we've consumed it
305- other. drop_with_heap ( heap) ;
306- Ok ( true )
307- }
308- Value :: InternString ( string_id) => {
309- self . 0 . push_str ( interns. get_str ( * string_id) ) ;
310- Ok ( true )
311- }
312- _ => Ok ( false ) ,
313- }
314- }
315-
316282 fn py_call_attr (
317283 & mut self ,
318284 _self_id : HeapId ,
0 commit comments