diff options
Diffstat (limited to 'rustables/src/expr/immediate.rs')
-rw-r--r-- | rustables/src/expr/immediate.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/rustables/src/expr/immediate.rs b/rustables/src/expr/immediate.rs index b5be101..ff4ad04 100644 --- a/rustables/src/expr/immediate.rs +++ b/rustables/src/expr/immediate.rs @@ -50,6 +50,30 @@ impl<const N: usize> Expression for Immediate<[u8; N]> { Immediate::<u8>::get_raw_name() } + /// The raw data contained inside `Immediate` expressions can only be deserialized to + /// arrays of bytes, to ensure that the memory layout of retrieved data cannot be + /// violated. It is your responsibility to provide the correct length of the byte + /// data. If the data size is invalid, you will get the error + /// `DeserializationError::InvalidDataSize`. + /// + /// Example (warning, no error checking!): + /// ```rust + /// use std::ffi::CString; + /// use std::net::Ipv4Addr; + /// use std::rc::Rc; + /// + /// use rustables::{Chain, expr::{Immediate, Register}, ProtoFamily, Rule, Table}; + /// + /// let table = Rc::new(Table::new(&CString::new("mytable").unwrap(), ProtoFamily::Inet)); + /// let chain = Rc::new(Chain::new(&CString::new("mychain").unwrap(), table)); + /// let mut rule = Rule::new(chain); + /// rule.add_expr(&Immediate::new(42u8, Register::Reg1)); + /// for expr in Rc::new(rule).get_exprs() { + /// println!("{:?}", expr.decode_expr::<Immediate<[u8; 1]>>().unwrap()); + /// } + /// ``` + /// These limitations occur because casting bytes to any type of the same size + /// as the raw input would be *extremely* dangerous in terms of memory safety. // As casting bytes to any type of the same size as the input would // be *extremely* dangerous in terms of memory safety, // rustables only accept to deserialize expressions with variable-size data |