refactor(fakedns): FakeIPServer.get(domain) now returns Option<IpAddr>; cleaned unused deps

This commit is contained in:
Namilsk 2026-09-28 20:25:57 +03:00
parent 7954859517
commit bb417b8a6d
No known key found for this signature in database
GPG key ID: 2B2F0A4D870B4F9F
6 changed files with 52 additions and 29 deletions

View file

@ -42,7 +42,7 @@ pub trait FakeIPOptions {
ip_type: IPStrategies,
) -> Result<IpAddr, std::io::Error>;
async fn init_resolver(&mut self, link: String) -> Result<(), std::io::Error>;
fn get(&self, domain: &str) -> Result<IpAddr, std::io::Error>;
fn get(&self, domain: &str) -> Option<IpAddr>;
}
fn generate_ip_from(network: Ipv4Addr, prefix: u32) -> Ipv4Addr {
@ -62,17 +62,15 @@ impl FakeIPOptions for FakeIPServer {
/// Just gets an FakeIP addr from FakeIPStorage.
/// ```rust
/// x = FakeIPServer::new(/* params */);
/// x.add("nosystemd.org") // returns IpAddr, but if it dropped you can call
/// x.get("nosystemd.org").unwrap() // -> IpAddr
/// x.add("nosystemd.org"); // returns IpAddr, but if it dropped you can call
/// let addr = x.get("nosystemd.org"); // -> Option<IpAddr>
/// if addr.is_some() {
/// println("{}", addr.unwrap()); // -> IpAddr
/// }
/// ```
fn get(&self, domain: &str) -> Result<IpAddr, std::io::Error> {
self.entries.get(domain).copied().ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::NotFound,
format!("No FakeIP entry found for domain: {domain}"),
)
})
}
fn get(&self, domain: &str) -> Option<IpAddr> {
self.entries.get(domain).copied()
}
/// FakeIPServer function which init's integrated DNS resolver for
/// ```rust