namib-project / nftables-rs

Safe abstraction for nftables JSON API (libnftables-json).
https://crates.io/crates/nftables
Apache License 2.0
17 stars 11 forks source link

Improve API usability #21

Open jwhb opened 4 months ago

jwhb commented 4 months ago

Motivation

Concerns were raised regarding the usability of the API exposed by this crate. The definition of nftables structures may become very verbose:

// ...
    stmt::Statement::Match(stmt::Match {
        left: expr::Expression::BinaryOperation(expr::BinaryOperation::AND(
            Box::new(expr::Expression::Named(expr::NamedExpression::Meta(
                expr::Meta {
                    key: expr::MetaKey::Mark,
                },
            ))),
            Box::new(expr::Expression::Number(MASK)),
        )),
        right: expr::Expression::Number(MASK),
        op: stmt::Operator::EQ,
    }),
    stmt::Statement::Masquerade(None),
// ...

Users of this crate may wish to define nftables structures in a more concise way.

Goal

Proposal

bensialih commented 3 weeks ago

Great rust library. I think this would be really good along side better docs.