Last active
          September 29, 2023 16:15 
        
      - 
      
 - 
        
Save FGRibreau/918824a80aba1f675026551f6cd617a1 to your computer and use it in GitHub Desktop.  
    Convert a HeaderValue into a rust String
  
        
  
    
      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
    
  
  
    
  | /// Additional conversion methods for `HeaderValue`. | |
| pub trait HeaderValueExt { | |
| fn to_string(&self) -> String; | |
| } | |
| impl HeaderValueExt for HeaderValue { | |
| fn to_string(&self) -> String { | |
| self.to_str().unwrap_or_default().to_string() | |
| } | |
| } | |
| // Usage: | |
| let ok: Option<String> = request.headers().get("ok").map(|x| x.to_string()); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment