[go: up one dir, main page]

DisplayRedacted

Trait DisplayRedacted 

Source
pub trait DisplayRedacted {
    // Required methods
    fn fmt_redacted(&self, f: &mut Formatter<'_>) -> Result<(), Error>;
    fn fmt_unredacted(&self, f: &mut Formatter<'_>) -> Result<(), Error>;

    // Provided methods
    fn display_redacted(&self) -> impl Display { ... }
    fn display_unredacted(&self) -> impl Display { ... }
}
Expand description

A type that can be displayed in a redacted or un-redacted form, but which forces the caller to choose.

See Redactable for more discussion on redaction.

Unlike Redactable, this type is “inherently sensitive”: Types implementing DisplayRedacted should not typically implement Display.

For external types that implement Display, or for types which are usually not sensitive, Redacted is likely a better choice.

Required Methods§

Source

fn fmt_redacted(&self, f: &mut Formatter<'_>) -> Result<(), Error>

As Display::fmt, but write this object in its redacted form.

Source

fn fmt_unredacted(&self, f: &mut Formatter<'_>) -> Result<(), Error>

As Display::fmt, but write this object in its un-redacted form.

Provided Methods§

Source

fn display_redacted(&self) -> impl Display

Return a pointer wrapping this object that can be Displayed in redacted form if safe-logging is enabled.

(If safe-logging is not enabled, it will de displayed in its unredacted form.)

Source

fn display_unredacted(&self) -> impl Display

Return a pointer wrapping this object that can be Displayed in unredacted form.

Examples found in repository?
examples/server.rs (line 24)
12async fn main() -> Result<(), Whatever> {
13    println!("Connecting to tor network");
14    let tor = Tor::new(TorConfig::default())
15        .await
16        .whatever_context("unable to connect to tor network")?;
17    println!("Connected!");
18    let service = tor
19        .service("hello")
20        .whatever_context("unable to create service")?;
21
22    println!(
23        "Onion address: {}",
24        service.onion_address().unwrap().display_unredacted()
25    );
26
27    let app = Route::new().at("/hello/:name", get(hello)).with(Tracing);
28    Server::new(service)
29        .name("hello-world")
30        .run(app)
31        .await
32        .expect("server error");
33    Ok(())
34}

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.

Implementations on Foreign Types§

Source§

impl DisplayRedacted for HsId

Source§

fn fmt_unredacted(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Source§

fn fmt_redacted(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Source§

impl<'a, T> DisplayRedacted for &'a T
where T: DisplayRedacted + ?Sized,

Source§

fn display_redacted(&self) -> impl Display

Source§

fn display_unredacted(&self) -> impl Display

Source§

fn fmt_redacted(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Source§

fn fmt_unredacted(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Implementors§