Struct DynOption

Source
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

Source

pub fn new<F>(current: T, filter: F) -> Self
where F: Fn(&T) -> MessageOption + Send + 'static,

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§

Source§

impl<T: Message> Message for DynOption<T>

Dynamic option is a transparent object for the inner

Source§

fn write(&self, writer: &mut dyn Write) -> RdpResult<()>

Transparent

Source§

fn read(&mut self, reader: &mut dyn Read) -> RdpResult<()>

Transparent

Source§

fn length(&self) -> u64

Transparent

Source§

fn visit(&self) -> DataType<'_>

Transparent

Source§

fn options(&self) -> MessageOption

Transparent

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V