TvfFilter

Trait TvfFilter 

Source
pub trait TvfFilter {
    // Required method
    fn filter<T: Tvf>(tvf: T) -> T;

    // Provided method
    fn mask_tvf_str_field<T: Tvf>(tvf: T, id: usize, fill_char: &str) -> T { ... }
}
Available on crate feature msg only.
Expand description

Trait to define a TVF1 filter. Useful to filter sensitive data.

use prosa_utils::msg::tvf::{Tvf, TvfFilter};
use prosa_utils::msg::simple_string_tvf::SimpleStringTvf;

enum TvfTestFilter {}

impl TvfFilter for TvfTestFilter {
    fn filter<T: Tvf>(mut buf: T) -> T {
        buf = <TvfTestFilter as TvfFilter>::mask_tvf_str_field(buf, 1, "*");
        <TvfTestFilter as TvfFilter>::mask_tvf_str_field(buf, 2, "0")
    }
}

let mut tvf: SimpleStringTvf = Default::default();
tvf.put_string(1, "plain");
tvf.put_string(2, "1234");
tvf.put_string(3, "clear");

let tvf_filtered = TvfTestFilter::filter(tvf);
assert_eq!(Ok(std::borrow::Cow::Owned(String::from("*****"))), tvf_filtered.get_string(1));
assert_eq!(Ok(std::borrow::Cow::Owned(String::from("0000"))), tvf_filtered.get_string(2));
assert_eq!(Ok(std::borrow::Cow::Owned(String::from("clear"))), tvf_filtered.get_string(3));

  1. Tag Value Format 

Required Methods§

Source

fn filter<T: Tvf>(tvf: T) -> T

Method to filter the TVF buffer

Provided Methods§

Source

fn mask_tvf_str_field<T: Tvf>(tvf: T, id: usize, fill_char: &str) -> T

Function to mask a TVF string field

Replace in the TVF buf the string value at the id with a fill character

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§