Function i_dunno::encode[][src]

pub fn encode(
    ip_addr: IpAddr,
    required_confusion_level: ConfusionLevel
) -> Option<String>

Encode an IP address into a random, valid I-DUNNO representation at the given confusion level.

Returns None if there are no possible encodings.

If there are many possible encodings, this function generates 10, and chooses one of those at random.

The output of this function MAY be presented to humans, as recommended by RFC8771.

Examples

use std::net::{Ipv4Addr, Ipv6Addr};
use i_dunno::{encode, ConfusionLevel};
let x = encode(
    "0.0.1.1".parse().unwrap(),
    ConfusionLevel::Delightful,
);
assert_eq!(x, None);

let a: String = encode(
    "::16:164".parse().unwrap(),
    ConfusionLevel::Minimum,
).unwrap();
assert_eq!(
    a,
    "\u{0}\u{0}\u{0}\u{0}\u{0}\u{0}\u{0}\u{0}\u{0}\u{0}\u{0}\u{0}\u{0}\u{0}\u{0}\u{2c02}d"
)