pub struct DynOption<T> { /* private fields */ }
Implementations§
Source§impl<T> DynOption<T>
The filter impl
A filter work like a proxy pattern for an inner object
impl<T> DynOption<T>
The filter impl A filter work like a proxy pattern for an inner object
Sourcepub fn new<F>(current: T, filter: F) -> Self
pub fn new<F>(current: T, filter: F) -> Self
Create a new filter from a callback Callback may return a list of field name taht will be skip by the component reader
The following example add a dynamic skip option
§Example
#[macro_use]
let message = component![
"flag" => DynOption::new(U32::LE(1), |flag| {
if flag.inner() == 1 {
return MessageOption::SkipField("depend".to_string());
}
else {
return MessageOption::None;
}
}),
"depend" => U32::LE(0)
];
assert_eq!(message.length(), 4);
The next example use dynamic option to set a size to a value
§Example
#[macro_use]
let mut message = component![
"Type" => DynOption::new(U32::LE(0), |flag| {
MessageOption::Size("Value".to_string(), flag.inner() as usize)
}),
"Value" => Vec::<u8>::new()
];
let mut stream = Cursor::new(vec![1,0,0,0,1]);
message.read(&mut stream).unwrap();
assert_eq!(cast!(DataType::Slice, message["Value"]).unwrap().len(), 1);
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for DynOption<T>where
T: Freeze,
impl<T> !RefUnwindSafe for DynOption<T>
impl<T> Send for DynOption<T>where
T: Send,
impl<T> !Sync for DynOption<T>
impl<T> Unpin for DynOption<T>where
T: Unpin,
impl<T> !UnwindSafe for DynOption<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more