Skip to content

Commit

Permalink
feat: make net macros usable without std
Browse files Browse the repository at this point in the history
  • Loading branch information
ROMemories committed Jan 23, 2025
1 parent bb629fd commit b92de87
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion const-str/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ proc = ["dep:const-str-proc-macro"]
regex = ["proc", "const-str-proc-macro?/regex"]
http = ["proc", "const-str-proc-macro?/http"]
case = ["proc", "const-str-proc-macro?/heck"]
all = ["std", "proc", "regex", "http", "case"]
all = ["proc", "regex", "http", "case"]
unstable = []

[package.metadata.docs.rs]
Expand Down
5 changes: 2 additions & 3 deletions const-str/src/__ctfe/net.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use core::net::{IpAddr, Ipv4Addr, Ipv6Addr};

struct Parser<'a> {
s: &'a [u8],
Expand Down Expand Up @@ -293,15 +293,14 @@ pub const fn expect_ip(s: &str) -> IpAddr {
///
/// # Examples
/// ```
/// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
/// use core::net::{IpAddr, Ipv4Addr, Ipv6Addr};
/// use const_str::ip_addr;
///
/// const LOCALHOST_V4: Ipv4Addr = ip_addr!(v4, "127.0.0.1");
/// const LOCALHOST_V6: Ipv6Addr = ip_addr!(v6, "::1");
///
/// const LOCALHOSTS: [IpAddr;2] = [ip_addr!("127.0.0.1"), ip_addr!("::1")];
/// ```
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[macro_export]
macro_rules! ip_addr {
(v4, $s:expr) => {
Expand Down
9 changes: 3 additions & 6 deletions const-str/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
clippy::missing_inline_in_public_items,
clippy::implicit_return
)]
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![cfg_attr(not(test), no_std)]
#![cfg_attr(docsrs, feature(doc_cfg))]

#[allow(unused_macros)]
Expand Down Expand Up @@ -80,11 +80,8 @@ pub mod __ctfe {
mod hex;
pub use self::hex::*;

#[cfg(feature = "std")]
item_group! {
mod net;
pub use self::net::*;
}
mod net;
pub use self::net::*;

mod parse;
pub use self::parse::*;
Expand Down

0 comments on commit b92de87

Please sign in to comment.