Skip to content

Commit

Permalink
Make default value for ParseOptions as true.
Browse files Browse the repository at this point in the history
Also, add a comment specifying calls will fail unless the options are set to false explicitly until the library is relatively complete.
  • Loading branch information
mmynk committed Nov 21, 2023
1 parent f1117b6 commit fd4fcab
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
//!
//! // Get list of tc qdiscs or classes
//! let qdiscs = ParseOptions::new()
//! .fail_on_unknown_netlink_message(true)
//! .fail_on_unknown_attribute(false)
//! .fail_on_unknown_option(false)
//! .tc(messages.clone()).unwrap();
//!
//! // Get list of links
Expand Down Expand Up @@ -58,7 +59,7 @@ pub enum RtNetlinkMessage {

/// `OpenOptions` provides options for controlling how `netlink-tc` parses netlink messages.
/// By default, unknown attributes and options are ignored.
#[derive(Debug, Default)]
#[derive(Debug)]
pub struct ParseOptions {
fail_on_unknown_netlink_message: bool,
fail_on_unknown_attribute: bool,
Expand All @@ -67,11 +68,15 @@ pub struct ParseOptions {

impl ParseOptions {
/// Creates a new set of options with all flags set to false.
/// By default, the call fails on unknown netlink messages, attributes or options.
///
/// NOTE: Using the default options will lead to the calls failing until the library is complete.
/// Thus, the caller must explicitly set the required options to false until then.
pub fn new() -> Self {
Self {
fail_on_unknown_netlink_message: false,
fail_on_unknown_attribute: false,
fail_on_unknown_option: false,
fail_on_unknown_netlink_message: true,
fail_on_unknown_attribute: true,
fail_on_unknown_option: true,
}
}

Expand Down Expand Up @@ -105,9 +110,9 @@ impl ParseOptions {
/// use netlink_tc::ParseOptions;
///
/// let queues = ParseOptions::new()
/// .fail_on_unknown_netlink_message(true)
/// .fail_on_unknown_attribute(true)
/// .fail_on_unknown_option(true)
/// .fail_on_unknown_netlink_message(false)
/// .fail_on_unknown_attribute(false)
/// .fail_on_unknown_option(false)
/// .tc(vec![]); // init with netlink messages
/// ```
pub fn tc(&self, messages: Vec<NetlinkMessage<RtnlMessage>>) -> Result<Vec<Tc>, Error> {
Expand Down

0 comments on commit fd4fcab

Please sign in to comment.