Forked from koopa1338/gist:8d9476c653a0488090a1be33be25ae07
          
        
    
          Created
          December 11, 2024 10:55 
        
      - 
      
 - 
        
Save jonjack/76ae94ad83c07ddb1cd2ee286f69e564 to your computer and use it in GitHub Desktop.  
    Rust string types
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | String: | |
| buffer | |
| / capacity | |
| / / length | |
| / / / | |
| +–––+–––+–––+ | |
| stack frame │ • │ 8 │ 6 │ <- my_string: String | |
| +–│–+–––+–––+ | |
| │ | |
| [–│–––––––– capacity –––––––––––] | |
| │ | |
| +–V–+–––+–––+–––+–––+–––+–––+–––+ | |
| heap │ F │ e │ r │ r │ i │ s │ │ │ | |
| +–––+–––+–––+–––+–––+–––+–––+–––+ | |
| [––––––– length ––––––––] | |
| &str: | |
| my_str: String sub_str: &str | |
| [–––––––––––-–] [–––––––] | |
| +–––+––––+––––+–––+–––+–––+ | |
| stack frame │ • │ 16 │ 13 │ │ • │ 6 │ | |
| +–│–+––––+––––+–––+–│–+–––+ | |
| │ │ | |
| │ +–+ | |
| │ │ | |
| │ │ | |
| │ [–│––––– str –––––––] | |
| +–V–+–––+–––+–––+–––+–V–+–––+–-–+–––+–––+ | |
| heap │ R │ u │ s │ t │ │ r │ o │ c │ k │ s │ | |
| +–––+–––+–––+–––+–––+–––+–––+–––+–––+–––+ | |
| string literals: | |
| my_str: &str | |
| [–––––––] | |
| +–––+–––+ | |
| stack frame │ • │ 4 │ | |
| +–│–+–––+ | |
| │ | |
| +––+ | |
| │ | |
| preallocated +–V–+–––+–––+–––+ | |
| read-only │ R │ u │ s │ t │ | |
| memory +–––+–––+–––+–––+ | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment