Skip to content

Common structs lack Default trait #286

Closed
@raphaelcohn

Description

@raphaelcohn

Whilst implementing wrappers around sysctl, I had to create a mutable value on the stack which would be overwritten by sysctl. To make the wrapper useful, I wanted to make it generic in <T: Default>. For c_int, etc, this is fine, but structs like timeval this isn't. Rust's rules mean I can't impl the Default trait to structs defined in libc.

My workaround is to have two wrapper functions, one which takes <T> and has an extra user-supplied default, and one that takes <T: Default>.

A simple solution to this would be to have the s! macro generate a default trait for all structs like this. In the near term, however, would you be open to this sort of change? Or is it something you don't feel belongs in libc?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions