mirror of
https://github.com/nftables-rs/nftables-rs.git
synced 2026-10-28 16:00:54 +00:00
This fails to build on 1.65:
```
error[E0277]: the trait bound `[SetItem]: ToOwned` is not satisfied in `Expression`
--> src/stmt.rs:245:14
|
245 | pub dev: Option<Expression>,
| ^^^^^^^^^^^^^^^^^^ within `Expression`, the trait `ToOwned` is not implemented for `[SetItem]`, which is required by `Expression: Sized`
|
= help: the trait `ToOwned` is implemented for `[T]`
note: required because it appears within the type `Expression`
--> src/expr.rs:10:10
|
10 | pub enum Expression {
| ^^^^^^^^^^
note: required by an implicit `Sized` bound in `std::option::Option`
--> /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/option.rs:572:1
...and many, many similar errors
```
It compiles successfully on Rust >=1.79, so this commit can be reverted once our MSRV reaches it.
56 lines
2.0 KiB
Rust
56 lines
2.0 KiB
Rust
use nftables::{expr::*, schema::*, stmt::*, types::*};
|
|
use std::borrow::Cow;
|
|
|
|
#[test]
|
|
fn test_serialize() {
|
|
let _a: Nftables = Nftables {
|
|
objects: Cow::Owned(vec![
|
|
NfObject::CmdObject(NfCmd::Add(NfListObject::Table(Table {
|
|
family: NfFamily::INet,
|
|
name: Cow::Borrowed("namib"),
|
|
handle: None,
|
|
}))),
|
|
NfObject::CmdObject(NfCmd::Add(NfListObject::Chain(Chain {
|
|
family: NfFamily::INet,
|
|
table: Cow::Borrowed("namib"),
|
|
name: Cow::Borrowed("one_chain"),
|
|
newname: None,
|
|
handle: None,
|
|
_type: Some(NfChainType::Filter),
|
|
hook: Some(NfHook::Forward),
|
|
prio: None,
|
|
dev: None,
|
|
policy: Some(NfChainPolicy::Accept),
|
|
}))),
|
|
NfObject::CmdObject(NfCmd::Add(NfListObject::Rule(Rule {
|
|
family: NfFamily::INet,
|
|
table: Cow::Borrowed("namib"),
|
|
chain: Cow::Borrowed("one_chain"),
|
|
expr: Cow::Owned(vec![
|
|
Statement::Match(Match {
|
|
left: Expression::List(vec![
|
|
Expression::Number(123),
|
|
Expression::String(Cow::Borrowed("asd")),
|
|
]),
|
|
right: Expression::Named(NamedExpression::CT(CT {
|
|
key: Cow::Borrowed("state"),
|
|
family: None,
|
|
dir: None,
|
|
})),
|
|
op: Operator::EQ,
|
|
}),
|
|
Statement::Drop(Some(Drop {})),
|
|
]),
|
|
handle: None,
|
|
index: None,
|
|
comment: None,
|
|
}))),
|
|
]),
|
|
};
|
|
|
|
let j = serde_json::to_string(&_a).unwrap();
|
|
let result: Nftables = serde_json::from_str(&j).unwrap();
|
|
println!("JSON: {}", j);
|
|
println!("Parsed: {:?}", result);
|
|
}
|