-
Notifications
You must be signed in to change notification settings - Fork 13
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
feat(config): Implement std::default::Default #19
Conversation
ea87f1b
to
c890bf1
Compare
(Here not the project lead, some random Joe) |
Ah. @stappersg, no worries! Happy to explain :) It's fairly common in Rust for types to implement certain Traits, (or interfaces in other languages), for standard behaviors. One of those behaviors is constructing a default representation of a type. Check out the docs on the trait here: https://doc.rust-lang.org/std/default/trait.Default.html I typically do this when I'd like to create a config with specific values, but I don't really care about the other values. Let's take for example someone wanting to run their TFTP server on the IPV6 localhost ( let config = Config {
ip_address: IpAddr::V6(Ipv6Addr::LOCALHOST),
..Config::default()
}; And rely on the default implementation to do the rest. It's possible to do something similar to the above with the existing let config = Config {
ip_address: IpAddr::V6(Ipv6Addr::LOCALHOST),
..Config::new([].into_iter()).expect("Config building with no args should be fine, and my application depends on that")
}; |
Looks great initially, I’ll take a closer look when I get home. Thank you for your addition! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, I just only have one small styling request.
I'd like to use Config::default in my own code when constructing a `Config`. Let's implement the Default trait so that others can use it without wrapping our struct due to ownership rules.
c890bf1
to
5b49110
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Hey! I'm hoping to use this library for a project of mine, and wanted to instantiate a Config using the Default trait. Thought I'd put up a PR for it! Lmk what you think!