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

Improve std::fs::Metadata Debug representation #124103

Merged
merged 1 commit into from Apr 21, 2024

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Apr 18, 2024

  • Remove duplication of mode between file_type and permissions, which both involve operating on the same mode_t integer
  • Add is_symlink
  • Add len in bytes
  • Remove Ok wrapping around modified, accessed, created, which eliminates 6 useless lines
BeforeAfter
Metadata {
    file_type: FileType(
        FileType {
            mode: 0o100600 (-rw-------),
        },
    ),
    is_dir: false,
    is_file: true,
    permissions: Permissions(
        FilePermissions {
            mode: 0o100600 (-rw-------),
        },
    ),
    modified: Ok(
        SystemTime {
            tv_sec: 1713402981,
            tv_nsec: 682983531,
        },
    ),
    accessed: Ok(
        SystemTime {
            tv_sec: 1713402983,
            tv_nsec: 206999623,
        },
    ),
    created: Ok(
        SystemTime {
            tv_sec: 1713402981,
            tv_nsec: 682983531,
        },
    ),
    ..
}
Metadata {
    file_type: FileType {
        is_file: true,
        is_dir: false,
        is_symlink: false,
        ..
    },
    permissions: Permissions(
        FilePermissions {
            mode: 0o100600 (-rw-------),
        },
    ),
    len: 2096,
    modified: SystemTime {
        tv_sec: 1713402981,
        tv_nsec: 682983531,
    },
    accessed: SystemTime {
        tv_sec: 1713402983,
        tv_nsec: 206999623,
    },
    created: SystemTime {
        tv_sec: 1713402981,
        tv_nsec: 682983531,
    },
    ..
}






Generated by:

fn main() {
    println!("{:#?}", std::fs::metadata("Cargo.toml").unwrap());
}

Before:

    Metadata {
        file_type: FileType(
            FileType {
                mode: 0o100600 (-rw-------),
            },
        ),
        is_dir: false,
        is_file: true,
        permissions: Permissions(
            FilePermissions {
                mode: 0o100600 (-rw-------),
            },
        ),
        modified: Ok(
            SystemTime {
                tv_sec: 1713402981,
                tv_nsec: 682983531,
            },
        ),
        accessed: Ok(
            SystemTime {
                tv_sec: 1713402983,
                tv_nsec: 206999623,
            },
        ),
        created: Ok(
            SystemTime {
                tv_sec: 1713402981,
                tv_nsec: 682983531,
            },
        ),
        ..
    }

After:

    Metadata {
        file_type: FileType {
            is_dir: false,
            is_file: true,
            is_symlink: false,
            ..
        },
        permissions: Permissions(
            FilePermissions {
                mode: 0o100600 (-rw-------),
            },
        ),
        len: 2096,
        modified: SystemTime {
            tv_sec: 1713402981,
            tv_nsec: 682983531,
        },
        accessed: SystemTime {
            tv_sec: 1713402983,
            tv_nsec: 206999623,
        },
        created: SystemTime {
            tv_sec: 1713402981,
            tv_nsec: 682983531,
        },
        ..
    }
@rustbot
Copy link
Collaborator

rustbot commented Apr 18, 2024

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 18, 2024
@Mark-Simulacrum
Copy link
Member

@bors r+ rollup=iffy

@bors
Copy link
Contributor

bors commented Apr 20, 2024

📌 Commit fdf93bb has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 20, 2024
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Apr 20, 2024
…lacrum

Improve std::fs::Metadata Debug representation

- Remove duplication of `mode` between `file_type` and `permissions`, which both involve operating on the same mode_t integer
- Add `is_symlink`
- Add `len` in bytes
- Remove Ok wrapping around `modified`, `accessed`, `created`, which eliminates 6 useless lines

<table>
<tr><th>Before</th><th>After</th></tr>
<tr><td>

```console
Metadata {
    file_type: FileType(
        FileType {
            mode: 0o100600 (-rw-------),
        },
    ),
    is_dir: false,
    is_file: true,
    permissions: Permissions(
        FilePermissions {
            mode: 0o100600 (-rw-------),
        },
    ),
    modified: Ok(
        SystemTime {
            tv_sec: 1713402981,
            tv_nsec: 682983531,
        },
    ),
    accessed: Ok(
        SystemTime {
            tv_sec: 1713402983,
            tv_nsec: 206999623,
        },
    ),
    created: Ok(
        SystemTime {
            tv_sec: 1713402981,
            tv_nsec: 682983531,
        },
    ),
    ..
}
```
</td><td>

```console
Metadata {
    file_type: FileType {
        is_file: true,
        is_dir: false,
        is_symlink: false,
        ..
    },
    permissions: Permissions(
        FilePermissions {
            mode: 0o100600 (-rw-------),
        },
    ),
    len: 2096,
    modified: SystemTime {
        tv_sec: 1713402981,
        tv_nsec: 682983531,
    },
    accessed: SystemTime {
        tv_sec: 1713402983,
        tv_nsec: 206999623,
    },
    created: SystemTime {
        tv_sec: 1713402981,
        tv_nsec: 682983531,
    },
    ..
}

```
</td></tr></table>

Generated by:

```rust
fn main() {
    println!("{:#?}", std::fs::metadata("Cargo.toml").unwrap());
}
```
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 20, 2024
Rollup of 11 pull requests

Successful merges:

 - rust-lang#123379 (Print note with closure signature on type mismatch)
 - rust-lang#123967 (static_mut_refs: use raw pointers to remove the remaining FIXME)
 - rust-lang#123976 (Use fake libc in core test)
 - rust-lang#123986 (lint-docs: Add redirects for renamed lints.)
 - rust-lang#124053 (coverage: Branch coverage tests for lazy boolean operators)
 - rust-lang#124071 (Add llvm-bitcode-linker to build manifest)
 - rust-lang#124103 (Improve std::fs::Metadata Debug representation)
 - rust-lang#124132 (llvm RustWrapper: explain OpBundlesIndirect argument type)
 - rust-lang#124191 (Give a name to each distinct manipulation of pretty-printer FixupContext)
 - rust-lang#124193 (Miri subtree update)
 - rust-lang#124196 (mir-opt tests: rename unit-test -> test-mir-pass)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 20, 2024
Rollup of 10 pull requests

Successful merges:

 - rust-lang#123379 (Print note with closure signature on type mismatch)
 - rust-lang#123967 (static_mut_refs: use raw pointers to remove the remaining FIXME)
 - rust-lang#123976 (Use fake libc in core test)
 - rust-lang#123986 (lint-docs: Add redirects for renamed lints.)
 - rust-lang#124053 (coverage: Branch coverage tests for lazy boolean operators)
 - rust-lang#124071 (Add llvm-bitcode-linker to build manifest)
 - rust-lang#124103 (Improve std::fs::Metadata Debug representation)
 - rust-lang#124132 (llvm RustWrapper: explain OpBundlesIndirect argument type)
 - rust-lang#124191 (Give a name to each distinct manipulation of pretty-printer FixupContext)
 - rust-lang#124196 (mir-opt tests: rename unit-test -> test-mir-pass)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 418a078 into rust-lang:master Apr 21, 2024
12 checks passed
@rustbot rustbot added this to the 1.79.0 milestone Apr 21, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 21, 2024
Rollup merge of rust-lang#124103 - dtolnay:metadatadebug, r=Mark-Simulacrum

Improve std::fs::Metadata Debug representation

- Remove duplication of `mode` between `file_type` and `permissions`, which both involve operating on the same mode_t integer
- Add `is_symlink`
- Add `len` in bytes
- Remove Ok wrapping around `modified`, `accessed`, `created`, which eliminates 6 useless lines

<table>
<tr><th>Before</th><th>After</th></tr>
<tr><td>

```console
Metadata {
    file_type: FileType(
        FileType {
            mode: 0o100600 (-rw-------),
        },
    ),
    is_dir: false,
    is_file: true,
    permissions: Permissions(
        FilePermissions {
            mode: 0o100600 (-rw-------),
        },
    ),
    modified: Ok(
        SystemTime {
            tv_sec: 1713402981,
            tv_nsec: 682983531,
        },
    ),
    accessed: Ok(
        SystemTime {
            tv_sec: 1713402983,
            tv_nsec: 206999623,
        },
    ),
    created: Ok(
        SystemTime {
            tv_sec: 1713402981,
            tv_nsec: 682983531,
        },
    ),
    ..
}
```
</td><td>

```console
Metadata {
    file_type: FileType {
        is_file: true,
        is_dir: false,
        is_symlink: false,
        ..
    },
    permissions: Permissions(
        FilePermissions {
            mode: 0o100600 (-rw-------),
        },
    ),
    len: 2096,
    modified: SystemTime {
        tv_sec: 1713402981,
        tv_nsec: 682983531,
    },
    accessed: SystemTime {
        tv_sec: 1713402983,
        tv_nsec: 206999623,
    },
    created: SystemTime {
        tv_sec: 1713402981,
        tv_nsec: 682983531,
    },
    ..
}

```
</td></tr></table>

Generated by:

```rust
fn main() {
    println!("{:#?}", std::fs::metadata("Cargo.toml").unwrap());
}
```
@dtolnay dtolnay deleted the metadatadebug branch April 21, 2024 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants