Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Deserialize impl to make input lifetime less constrained #15

Merged
merged 1 commit into from
Nov 25, 2023

Commits on Nov 24, 2023

  1. Fix Deserialize impl to make input lifetime less constrained

    Example code:
    
        use mediatype::MediaType;
        use serde_derive::Deserialize;
        use std::path::PathBuf;
        use std::time::SystemTime;
    
        #[derive(Deserialize)]
        struct FileMetadata<'a> {
            file_path: PathBuf,
            last_updated: SystemTime,
            #[serde(borrow)]
            mediatype: MediaType<'a>,
        }
    
    Without this PR:
    
        error: lifetime may not live long enough
          --> src/main.rs:10:5
           |
        6  |   #[derive(Deserialize)]
           |            ----------- lifetime `'de` defined here
        7  |   pub struct FileMetadata<'a> {
           |                           -- lifetime `'a` defined here
        ...
        10 | /     #[serde(borrow)]
        11 | |     pub mediatype: MediaType<'a>,
           | |________________________________^ requires that `'a` must outlive `'de`
           |
           = help: consider adding the following bound: `'a: 'de`
    
    After this PR: works.
    dtolnay committed Nov 24, 2023
    Configuration menu
    Copy the full SHA
    b5c167a View commit details
    Browse the repository at this point in the history