From 790c04f3ecb507a1c5ae9b5c4252452781eda6c4 Mon Sep 17 00:00:00 2001 From: Vinnie Magro Date: Mon, 9 Sep 2024 08:11:35 -0700 Subject: [PATCH] implement for std::net::IpAddr Summary: I want to wrap `IpAddr` in a following diff, so I'm implementing `Allocative` to make that more natural. Reviewed By: pallotron Differential Revision: D62303400 fbshipit-source-id: da973460b78ca7b980dc60aca5364aa8f09fce19 --- allocative/src/impls/std.rs | 1 + allocative/src/impls/std/net.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 allocative/src/impls/std/net.rs diff --git a/allocative/src/impls/std.rs b/allocative/src/impls/std.rs index 49e07bb..df566de 100644 --- a/allocative/src/impls/std.rs +++ b/allocative/src/impls/std.rs @@ -12,6 +12,7 @@ mod cell; mod collections; mod function; mod mem; +mod net; mod primitive; mod sync; mod time; diff --git a/allocative/src/impls/std/net.rs b/allocative/src/impls/std/net.rs new file mode 100644 index 0000000..29a2fbf --- /dev/null +++ b/allocative/src/impls/std/net.rs @@ -0,0 +1,33 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under both the MIT license found in the + * LICENSE-MIT file in the root directory of this source tree and the Apache + * License, Version 2.0 found in the LICENSE-APACHE file in the root directory + * of this source tree. + */ + +use std::net::IpAddr; +use std::net::Ipv4Addr; +use std::net::Ipv6Addr; + +use crate::allocative_trait::Allocative; +use crate::visitor::Visitor; + +impl Allocative for IpAddr { + fn visit<'a, 'b: 'a>(&self, visitor: &'a mut Visitor<'b>) { + visitor.enter_self_sized::().exit(); + } +} + +impl Allocative for Ipv4Addr { + fn visit<'a, 'b: 'a>(&self, visitor: &'a mut Visitor<'b>) { + visitor.enter_self_sized::().exit(); + } +} + +impl Allocative for Ipv6Addr { + fn visit<'a, 'b: 'a>(&self, visitor: &'a mut Visitor<'b>) { + visitor.enter_self_sized::().exit(); + } +}